开发者

ASP.Net check value with DBNULL

开发者 https://www.devze.com 2022-12-23 17:27 出处:网络
I have the following code foreach (DataRowView dr in Data) { if (dr == System.DBNull.Value) { nedID = 1; } }

I have the following code

foreach (DataRowView dr in Data)
        {
            if (dr == System.DBNull.Value)
            {
                nedID = 1;
            }
        }

but i get the following error Operator == cannot be applied to operands of type System.Data.DataRowView and System.DBNull

please can some one advice me on how i can check if开发者_StackOverflow社区 the value is null or DBNULL


You need to specify the field name or index.

foreach (DataRowView dr in Data)
{
    if (dr["nameOfField"] == System.DBNull.Value)
    {
        nedID = 1;
    }
}


You need to replace dr == System.DBNull.Value with...

Convert.IsDBNull(dr["somefield"])

which returns true if it's DBNnull

0

精彩评论

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