开发者

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

开发者 https://www.devze.com 2023-04-12 00:16 出处:网络
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 it开发者_开发问答em retrieved from the database is null.

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 it开发者_开发问答em 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)
0

精彩评论

暂无评论...
验证码 换一张
取 消