Solved

Using BindingSource Filters and Date Values

Posted on 2009-06-28
4
719 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

20 Experts available now in Live!

Get 1:1 Help Now