• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1688
  • Last Modified:

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?

3 Solutions
Hi MikeMCSD,

think that this answers your question : http://weblogs.sqlteam.com/justinb/archive/2004/04/11/1239.aspx

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.

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now