Select Null

  • Thread starter Thread starter Johan Karlsson
  • Start date Start date
J

Johan Karlsson

Hi!

When using the DataTable.Select method, can I select values that are NULL?

Example:

myRows = myDataset.myTable.Select("anotherId=NULL")

I've tried the code above, no errors but it doesn't filter out the rows with
a null value.

Thanks
Johan
 
When using the DataTable.Select method, can I select values that are NULL?

Example:

myRows = myDataset.myTable.Select("anotherId=NULL")

I've tried the code above, no errors but it doesn't filter out the rows with
a null value.

Use something like:

myDataSet.myTable.Select("ISNULL(anotherId,'[[[XXX]]]')='[[[XXX]]]'");

where [[[XXX]]] is some value which won't appear in your table. I know
it's horrible, but I think that's all you can do.
 
Oops it should be: ISNULL(anotherId, 1) =1

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Miha Markic said:
Hi Johan,

Try using "ISNULL(anotherId, 1, 0) = 1"

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Johan Karlsson said:
Hi!

When using the DataTable.Select method, can I select values that are NULL?

Example:

myRows = myDataset.myTable.Select("anotherId=NULL")

I've tried the code above, no errors but it doesn't filter out the rows with
a null value.

Thanks
Johan
 
Oops it should be: ISNULL(anotherId, 1) =1

Except that will also include things with an ID of 1. You need to pick
a value which won't otherwise come up - which can be easier said than
done in some situations.

It's ridiculous that there isn't a *real* ISNULL operator (which just
computes whether an expression is NULL or not), but there we go...
 
Oops it should be: ISNULL(anotherId, 1) =1
Except that will also include things with an ID of 1. You need to pick
a value which won't otherwise come up - which can be easier said than
done in some situations.

Indeed.For the string field that example should probably work. Not for an
integer field, though.
It's ridiculous that there isn't a *real* ISNULL operator (which just
computes whether an expression is NULL or not), but there we go...

Yup.

Miha
 
Back
Top