Solved

Using BindingSource Filters and Date Values

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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