Link to home
Start Free TrialLog in
Avatar of Arnold Layne
Arnold LayneFlag for United States of America

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.

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>");
                }

Open in new window


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.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Avatar of Arnold Layne

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)
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i couldnt edit/delete my comment.  i didnt see @bob's and @Andy's comments when i post !
Thanks!