Arnold Layne
asked on
Checking for NULL value in SQLDataReader results for datetime field
I am checking to see if a datetime field from a SQLDataReader loop has been marked with a datetime.
None of my records have the "Next" field marked with a date and time in my test, so the "else" should be executed, but instead the "if" is executed. So my check for a null value is failing probably because there is something that I don't understand about datetime values. A quick second pair of corrective eyes from anyone would be helpful. Thanks.
if (myReader["Next"] != null)
{
Response.Write("<div id='delivered" + ID + "' class='buttons green' onclick='delivered(\"" + ID + "\");'>DELIVERED</div>");
}
else
{
Response.Write("<div id='next" + ID + "' class='buttons green' onclick='next(\"" + ID + "\");'>NEXT</div>");
}
None of my records have the "Next" field marked with a date and time in my test, so the "else" should be executed, but instead the "if" is executed. So my check for a null value is failing probably because there is something that I don't understand about datetime values. A quick second pair of corrective eyes from anyone would be helpful. Thanks.
ASKER
Repeat your answer and change it to DBNull.Value and I can mark it an A answer and 500 points. I just want to make sure that what I mark as a solution really is one. Thanks.
Try this
if (!myReader.isNull("Next"))
OR this
if (myReader["Next"]!=DBNull. Value)
if (!myReader.isNull("Next"))
OR this
if (myReader["Next"]!=DBNull.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i couldnt edit/delete my comment. i didnt see @bob's and @Andy's comments when i post !
ASKER
Thanks!
if (myReader["Next"] != DBNull)
http://stackoverflow.com/questions/221582/most-efficient-way-to-check-for-dbnull-and-then-assign-to-a-variable