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);
Call
What 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
Parameter
Description
value
Required. Object to test (often a data-reader field).
Return Value
Return Value
Description
true
Value is DBNull.
false
Anything 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));
}
}
Output
True
False
How It Works
DBNull.Value. The singleton database-null object.
IsDBNull true. Convert recognizes it.
42 false. Ordinary values are not DB null.
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));
}
}
Output
False
True
True
How It Works
C# null. IsDBNull returns false.
== null. Ordinary null check is true.
DBNull true. Only the DB null object matches.
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));
}
}
Output
no value
9
How It Works
Guard first. IsDBNull blocks a bad convert.
Message path. Print no value for DB null.
Real text. Second field converts with ToInt32.
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).