문제

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 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top