c# dataset value how to check if null

Posted on 2007-08-03
Last Modified: 2013-11-05
I have a dataset which I am trying to validate before saving to a database.

I get an error if I try to evaluate if it is null
                if ((dr.ResultCode == "Fail"))

II tried to check if it is null, but I can't.  How do you do it?
                if ( = DBNull)

Question by:jackjohnson44
    LVL 96

    Expert Comment

    by:Bob Learned
    if (dr.ResultCode.ToString() == "Fail")



    Author Comment

    Thanks, but how do you check if a value is null?
    LVL 96

    Expert Comment

    by:Bob Learned
    ToString will convert null to an empty string "".  

    If you want to check for DBNull, then you need:

      if (dr.ResultCode == DBNull.Value)


    Author Comment

    This does not work, it iwll fail

      if (dr.ResultCode == DBNull.Value)
    LVL 25

    Accepted Solution

    if (dr.IsResultCodeNull)
    if (dr.IsNull("ResultCode"))

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Title # Comments Views Activity
    WMI, model #, retrieving information 10 52
    Richtextbox formatting 8 18
    reading json from C# REST service 1 27
    DataGridView 2 11
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now