Community forum

Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.

Dear All,
I would like to create a condition in
by default, the code is the following:

"using System;
public class Test
// a VisualCron Condition must return a boolean which is the result of the Condition
public static bool MyCustomCondition(int valueX, int valueY)
return (valueX == valueY);

I would like to do something like this in

launch a sql statement on a sql server and bring the result: ok or nothing.

"using System;
public class Test
public static bool MyCustomCondition()
Server s;
Client c = new Client();
Connection conn = new Connection();
conn.Connectiontype = Connection.ConnectionT.Remote;
conn.Address = "GOSQL05\DWHPROD";
conn.UserName = "admininstrator";
conn.PassWord = "xxxx";
s = c.Connect(conn, true);
Dim comm As New SqlCommand("select 'OK' as statut from [ADMIN].[dbo].[Calendrier] where CalFirstWorkedDayOfMonth = 1 and CONVERT(char
(10), [CalDate],126) = CONVERT(char(10), GetDate(),126)", conn)
Dim reader As SqlDataReader = comm.ExecuteReader,
Dim dt As New DataTable,
Label1.Text = dr.Item("statut");
If Label1.Text = "OK"
Then return = 0;
return= 1
End If

Does someone to help me?

Forum information

If you are trying to make a condition in VC that connects to a database and returns true/false, we can probably help you with that. But before we do that, it seems you are trying to run some job on the first workday of each month, adjusting for holidays. Is that right? There are easier ways of accomplishing this in VC. I'll give you an example that avoids VB:

Create a job that runs once a day, and queries the database to check if it is the first worday in the month. Then you create a VisualCron condition (not a .NET condition) that checks the result of this job (the sql task in the job). By doing it this way, you are only running the query once a day, instead of every time a job is scheduled.

So the job would have an sql task with roughly this query. This assumes I have guessed correctly how you table looks like. I cast to Bit since that is the Sql server equivalent of Boolean. It also assumes that CalDate is unique and of type Date and not DateTime.

SELECT CAST(IIF(CalFirstWorkedDayOfMonth = 1, 1, 0) as Bit)
FROM [ADMIN].[dbo].[Calendrier]
WHERE [CalDate] = CAST( GetDate() AS DATE)

If you really want the VB version I can show you how to do it.

dear Thomas,

thanks a lot for your answer
your answer is very intresting.
I would appreciate to have a example for a condition like that.

Best regards,
ok. I haven't written vb in 15 years, so I'll give you a C# example:


remember to go to 'edit references' and add System.Data.dll. You have to change the query and connectionstring to suit your needs ofcourse. The connectionstring could be passed in as a parameter for example.

Vb would look something like this:


I'm not really recommending this approach, but you can test and see if it works for you.

Scroll to Top