When I add this to my where clause:
DueDate <= getDate() AND DueDate IS NOT null
I get a nice little failure that says: Could not create child: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.EvaluateException: The expression contains undefined function call getDate().
Any idea what I'm doing wrong?
Update Code in use:
private string getFilter(int mode) {
String filter = "";
if ((ALL_WORK_ORDERS & mode) == 0) {
if ((mode & OUTSTANDING_WORK_ORDERS) == OUTSTANDING_WORK_ORDERS) {
filter += "DueDate <= getDate() AND DueDate IS NOT null OR";
}
if ((mode & COMPLETED_WORK_ORDERS) == COMPLETED_WORK_ORDERS) {
filter += " FinishedDate IS NOT null";
}
}
filter = filter.Trim();
if (filter.EndsWith("OR")) {
filter = filter.Remove(filter.Length - 2);
}
return filter;
}
And it is getting used here:
tblWorkOrderBindingSource.Filter = getFilter(mode);
In the table, DueDate is type datetime.
Side note: I can run
SELECT [ID]
,[WorkDesc]
,[DueDate]
FROM [RentalEase].[dbo].[tblWorkOrder]
WHERE [DueDate] <= getDate() AND [DueDate] IS NOT null
in the MS SQL Server Management Studio Express without a problem.
Final Solution
private string getFilter(int mode) {
String filter = "";
if ((ALL_WORK_ORDERS & mode) == 0) {
if ((mode & OUTSTANDING_WORK_ORDERS) == OUTSTANDING_WORK_ORDERS) {
filter += "DueDate <= #" + DateTime.Now.ToShortDateString() + "# AND DueDate IS NOT null AND FinishedDate IS null OR";
}
if ((mode & COMPLETED_WORK_ORDERS) == COMPLETED_WORK_ORDERS) {
filter += " FinishedDate IS NOT null";
}
}
filter = filter.Trim();
if (filter.EndsWith("OR")) {
filter = filter.Remove(filter.Length - 2);
}
return filter;
}