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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
dejaanbuCommented:
Try this
if (!myReader.isNull("Next"))

OR this
if (myReader["Next"]!=DBNull.Value)
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

AndyAinscowFreelance programmer / ConsultantCommented:
if (myReader["Next"] != DBNull.Value)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dejaanbuCommented:
i couldnt edit/delete my comment.  i didnt see @bob's and @Andy's comments when i post !
0
BobHavertyComhAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.