SQL SERVER, DataRows and Null Dates

A

aaj

Hi all

I've spent ages looking on google for the answer to what I would guess is a
really common problem. Can anyone here help me out.

I read a view from SQL Server 2000 into a DataSet
From here I select some rows matching a certain criterea.
In the selected row is a column of type datetime that I'm interested in.
Before assigning a local variable to the value in the DataRow Column, I
simply want to check if its null

i.e.
DateTime InspectionDate;

foreach (DataRow CurrentRow in FinalSide)

{


if (sqldatenull.CompareTo(CurrentRow["upload_date"]) ????? or anything to
check for non null ????? == 0 )

{

InspectionDate= Convert.ToDateTime(CurrentRow["upload_date"]);

MessageBox.Show(InspectionDate.ToLongDateString());

}

}


I can't find anything to check if its empty of of its Null.

The best I can do is to use convert and catch the exception error, but I'm
guessing there must be a cleaner way of doing this.

thanks in advance

Andy
 
G

Guest

I think you're looking for IsDBNull method on the field or comparing the
field value to DBNULL.value. Hope this helps.
 
A

aaj

Many Thanks Thom

CurrentRow["upload_date"] != System.DBNull.Value

did the trick

thanks again

Andy



tbain said:
I think you're looking for IsDBNull method on the field or comparing the
field value to DBNULL.value. Hope this helps.
--
Thom


aaj said:
Hi all

I've spent ages looking on google for the answer to what I would guess is
a
really common problem. Can anyone here help me out.

I read a view from SQL Server 2000 into a DataSet
From here I select some rows matching a certain criterea.
In the selected row is a column of type datetime that I'm interested in.
Before assigning a local variable to the value in the DataRow Column, I
simply want to check if its null

i.e.
DateTime InspectionDate;

foreach (DataRow CurrentRow in FinalSide)

{


if (sqldatenull.CompareTo(CurrentRow["upload_date"]) ????? or anything
to
check for non null ????? == 0 )

{

InspectionDate= Convert.ToDateTime(CurrentRow["upload_date"]);

MessageBox.Show(InspectionDate.ToLongDateString());

}

}


I can't find anything to check if its empty of of its Null.

The best I can do is to use convert and catch the exception error, but
I'm
guessing there must be a cleaner way of doing this.

thanks in advance

Andy
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

You should check it agains DBNull.Value.

Next time you get something like this, it's very easy to know the type/value
of the column, just return that only row from the DB, then do a quickwatch
of :
theDataSet.Tables[0].Rows[0]["ColumnName"]

like that you will see both the type and the current value of the row and
you will know to what make the comparision with.


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top