C# Convert IsDBNull() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Convert

Definition

In C#, Convert.IsDBNull returns true when the argument is DBNull.Value—the special “database null” object used by ADO.NET readers.

This is different from a C# null reference. Always check DBNull before converting column values with ToInt32 or similar.

This is a static member of System.Convert. You call it with the type name, such as Convert.IsDBNull(...). Convert is the everyday API for converting between common CLR types in C#.

Syntax

Pass an object that might be DBNull.

C#
bool a = Convert.IsDBNull(DBNull.Value);
bool b = Convert.IsDBNull(null);
bool c = Convert.IsDBNull(42);
CallWhat it does
Convert.IsDBNull(DBNull.Value)true — database null.
Convert.IsDBNull(null)false — C# null is not DBNull.
Convert.IsDBNull(42)false — ordinary value.

DBNull.Value != null. Use IsDBNull before calling To* on data reader fields.

Library declarations
C#
public static bool IsDBNull(object? value);

Parameters

ParameterDescription
valueRequired. Object to test (often a data-reader field).

Return Value

Return ValueDescription
trueValue is DBNull.
falseAnything else, including C# null.

C# Examples

Example 1 — Detect Database Null

Compare DBNull with a normal int.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Convert.IsDBNull(DBNull.Value));
        Console.WriteLine(Convert.IsDBNull(42));
    }
}

How It Works

  1. DBNull.Value. The singleton database-null object.
  2. IsDBNull true. Convert recognizes it.
  3. 42 false. Ordinary values are not DB null.
  4. Reader fields. Same check applies to IDataRecord values.

Example 2 — Null Reference Is Different

Show that C# null is not DBNull.

C#
using System;

class Program {
    static void Main() {
        object? missing = null;
        Console.WriteLine(Convert.IsDBNull(missing));
        Console.WriteLine(missing == null);
        Console.WriteLine(Convert.IsDBNull(DBNull.Value));
    }
}

How It Works

  1. C# null. IsDBNull returns false.
  2. == null. Ordinary null check is true.
  3. DBNull true. Only the DB null object matches.
  4. Test both. Data layers may use either sentinel.

Example 3 — Skip Convert When DBNull

Avoid converting a DB null column.

C#
using System;

class Program {
    static void Main() {
        object field = DBNull.Value;
        if (Convert.IsDBNull(field)) {
            Console.WriteLine("no value");
        } else {
            Console.WriteLine(Convert.ToInt32(field));
        }
        object other = "9";
        Console.WriteLine(Convert.ToInt32(other));
    }
}

How It Works

  1. Guard first. IsDBNull blocks a bad convert.
  2. Message path. Print no value for DB null.
  3. Real text. Second field converts with ToInt32.
  4. Safe pattern. Always check reader nulls this way.

Frequently Asked Questions

No. DBNull.Value is a special object; C# null is a missing reference.
false.
ADO.NET data readers return it for SQL NULL columns.
No—check IsDBNull first or use GetValue patterns that handle nulls.
Objects can also be compared with ReferenceEquals(value, DBNull.Value).

Next: ToBase64CharArray()

Encode bytes into a Base64 char[] buffer you provide with System.Convert.

ToBase64CharArray() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful