Why is my comparison to null, of a value contained in a System.Data.DataRow object, failing?

StackOverflow https://stackoverflow.com/questions/7688794

문제

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?

도움이 되었습니까?

해결책

Try checking against DbNull.Value instead of null

다른 팁

Try:

if (System.Data.DataRow["foo"].IsDBNull)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top