Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using BindingSource Filters and Date Values

Posted on 2009-06-28
4
Medium Priority
?
758 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
paisleym earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

604 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