Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi folks,

I am trying to create a dataview where I want to filter the rows based on a date column containing Nulls.

 

No all the examples on filtering for null give

"Isnull(Col1,'Null Column') = 'Null Column'"

 

Now when I replace Col1 with my column name for my date column

"Isnull(Postal_Date,'Null Column') = 'Null Column'"

 

I get the following error

"Cannot perform '=' operation on System.DateTime and System.String."

 

Has anybody solved this problem or am I doing it all wrong.

 

:confused: :confused:

Hamlet
Posted

I have change the filter to use

"Postal_Date IS NULL"

and that works. Maybe I had the wrong end of the stick altogether with the IsNull method, cany anybody explain the difference.

Hamlet
Posted

IsNull() is a function that replaces a null value with a specified value. In other words if there where any null values in the column "UserName" the following would update those values to "No User Name" for the return of the select statement (it doesn't update the dataset itself):

 

"SELECT ISNULL(UserName, 'No User Name'), JoinDate FROM Members"

 

'IS NULL' is a comparission operator for null values, which you want to use.

Posted

The reason why I used the IsNull in the first place is that the online help for Dataview.RowFilter says

 

"To return only those columns with null values, use the following expression:

 

"Isnull(Col1,'Null Column') = 'Null Column'"

 

I tried it on non date comumns and it seemed to work OK

 

Is it a pecularity with date columns (see error message in origional post.)

 

The Is Null is working for me I am hust trying to understand why there is a difference between what works and ehat the online help says should work.

(Then again it is Microsoft, so maybe there is no reason)

Hamlet
Posted

That expression in the help file is saying in plain english to take all null columns and set there value to the string 'Null Column' and then return any rows where Col1 equals the string 'Null Column'. .NET cannot take a DateTime field and set it to a string value on it's own (there is no implicit cast) and thus the reason for the error. It is in truth a bad example in the help file and should read:

 

To return only those columns with null values, use the following expression:

"Col1 IS NULL"

 

I hope that clears things up for you.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...