C# Equivalent of VB’s IsDBNull


In VB, there is a IsDBNull function that checks to see if a value in a DataReader is null. It’s usage goes something like this:

VB

If IsDBNull(dr("first_name")) = False Then
    ' Do something, first_name is not null
End If

The C# equivalent of this would look something like this:

if (dr["first_name"] != System.DBNull.Value)
{
    // Do something, first_name is not null
}

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.