IsDBNull( ) or DBNull.Value

Which one is the better choice:

If Not IsDBNull(shipReader("Name")) Then

If Not shipReader("Name") Is DBNull.Value Then

I like the first one?  Is there a difference?

LVL 16
Who is Participating?
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.

Hi MikeMCSD,

think that this answers your question :


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
DBNull.Value is for passing a null to a datasource, IsDBNull is for reading from a datasource.

I would say the answer to this depends on how you are using it.

If you are using values from a dataset and using IsDBNull to check if a value is dbnull then I would create a strongly typed dataset because then it writes all of the null checking for you on fields that allow nulls.

If you are using values from a non strongly typed dataset or datareader and you are checking to make sure that the value is not null then I would use the IsDBNull function.

If you are trying to assign null to a database parameter then you should use DBNull.Value.

However I do feel this is personal preference, maybe it should be set in your working standards documents.

I feel it's the same as saying should you use String.Empty or "" it's personal preference or part of your company's standards.  

Whichever method you use, you should stick to that method throughout your application.
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

From novice to tech pro — start learning today.

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.