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.
LVL 9
BobHavertyComhAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
if (myReader["Next"] != DBNull.Value)
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
0
 
BobHavertyComhAuthor Commented:
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.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
dejaanbuCommented:
Try this
if (!myReader.isNull("Next"))

OR this
if (myReader["Next"]!=DBNull.Value)
0
 
dejaanbuCommented:
i couldnt edit/delete my comment.  i didnt see @bob's and @Andy's comments when i post !
0
 
BobHavertyComhAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.