IsDBNull( )  or  DBNull.Value

Posted on 2004-11-10
Last Modified: 2012-05-05

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?

Question by:MikeMCSD
    LVL 28

    Accepted Solution

    Hi MikeMCSD,

    think that this answers your question :

    LVL 17

    Assisted Solution

    DBNull.Value is for passing a null to a datasource, IsDBNull is for reading from a datasource.

    LVL 1

    Assisted Solution

    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

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now