Dealing with NULL data

Posted on 2011-05-03
Last Modified: 2012-05-11
I have a datetime database column.  I need to deal with a possible NULL.  Here's my line of code, which I thought would do it, but I get this error message:   Public member 'ToShortDateString' on type 'DBNull' not found.

the_admin_reviewer_date = IIf(IsDBNull(Reader.Item(25)), "", Reader.Item(25).ToShortDateString)

How do I deal with a NULL data value?
Question by:HLRosenberger
    LVL 23

    Accepted Solution

    The IIf will call all functions involved in the expression, true part, and false part before checking the expression result.  The alternative here is to use an If statement.

    If IsDBNull(Reader.Item(25)) Then
         the_admin_reviewer_date = ""
         the_admin_reviewer_date =  Reader.Item(25).ToShortDateString
    End If

    Open in new window

    More about IIf here:
    LVL 23

    Expert Comment


    the_admin_reviewer_date = If(IsDBNull(Reader.Item(25)), "", Reader.Item(25).ToShortDateString)

    Open in new window

    LVL 16

    Expert Comment

    by:Imran Javed Zia
    Please try this

    the_admin_reviewer_date = IIf(Reader.Item(25) Is DBNull.Value, "", Convert.ToDateTime(Reader.Item(25)).ToShortDateString())

    LVL 1

    Author Closing Comment

    Thanks.  You are correct - splitting it up does the trick

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    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

    15 Experts available now in Live!

    Get 1:1 Help Now