What is the best way to deal with DBNull's

后端 未结 14 1008
迷失自我
迷失自我 2020-12-02 15:45

I frequently have problems dealing with DataRows returned from SqlDataAdapters. When I try to fill in an object using code like this:



        
14条回答
  •  一整个雨季
    2020-12-02 16:14

    For some reason I've had problems with doing a check against DBNull.Value, so I've done things slightly different and leveraged a property within the DataRow object:

    if (row.IsNull["fooColumn"])
    {
       value = string.Empty();
    }
    {
    else
    {
       value = row["fooColumn"].ToString;
    }
    

提交回复
热议问题