1

I am converting an app's database from Access to MS SQL Server and encountered a problem with a line of code that checks to see if an item retrieved from the database is null.

It essentially looks like this:

if (System.Data.DataRow["foo"] == null)
{
    //do something
}

I know the value in column "foo" is null, but the check fails. It works against an Access database, but not MS SQL Server. I can see why. The call is returning "{}" instead of null. Why?

raven
  • 18,004
  • 16
  • 81
  • 112

2 Answers2

2

Try checking against DbNull.Value instead of null

Sergey Kudriavtsev
  • 10,328
  • 4
  • 43
  • 68
1

Try:

if (System.Data.DataRow["foo"].IsDBNull)
Marco
  • 56,740
  • 14
  • 129
  • 152