Solved

Using BindingSource Filters and Date Values

Posted on 2009-06-28
4
724 Views
Last Modified: 2012-08-14
Hi, I'm using VB 2005, WinForms. I have a BindingSourse set to a DataGridView on one of my Forms. I've been able to filter within the DataGridView without a problem, except for DATE values.
I keep getting the following error message when I try to filter for the presence of a date within a column.

ERROR MESSAGE:
----------------------
An unhandled exception of type 'System.Data.EvaluateException' occurred in System.Data.dll
Additional information: Cannot perform '=' operation on System.DateTime and System.String.
---------------------

I've tried coding the filter in the following ways:

bs.Filter = "CanceledDate = ' ' "
bs.Filter = "CanceledDate = 'dbNull.Value'"

Neither seems to work.

I simply need to know if a Date value is present in the cell or if the cell is empty. If there is no Date present, then the item has not been canceled. If there is a Date value present in the cell, then the item was indeed canceled.

This is a syntax problem, but I can't seem to get it right.

Thanks for your help,
Fulano
0
Comment
Question by:Mr_Fulano
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
paisleym earned 500 total points
ID: 24733811
Hi

Try

Canceled Date is null

hth
Marcelle
0
 

Author Comment

by:Mr_Fulano
ID: 24733838
Hi Marcelle, this is the error I got with the following line of code:

bs.Filter = "Canceled Date is null"

An unhandled exception of type 'System.Data.SyntaxErrorException' occurred in System.Data.dll

Additional information: Syntax error: Missing operand after 'Date' operator.

Any thoughts?

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24733842
Hi Marcelle, I fixed it...it should have been:

bs.Filter = "CanceledDate is null"  

Not

bs.Filter = "Canceled Date is null"

That worked!

Thanks!
0
 
LVL 4

Expert Comment

by:paisleym
ID: 24733843
Hi

Is Canceled Date the name of the field? If there is spaces in the field name that can cause errors. Yes, the 'is null' clause is more commonly used within the where clause of an sql query than in a filter, but if the date is sorted it may work. If Canceled Date contains a space it should be '  [Canceled Date] is null'

hth
Marcelle
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now