Follow @RoyOsherove on Twitter

Checking for NULL values

I was recently asked how to check if a DB value you have in your hands is NULL.

For one, you can use the System.DBNull class's 'Value' property to check this like so:

if (myVar==DBNull.Value)

Another way, is when you have a DataRow in your hands:

if(myDataRow.IsNull(myFieldName))

if(myDataRow.IsNull(myFieldIndex))

Geekier than thou

Registration-free COM interop