Finding null value in Dataset - DataRow.IsNull method vs ==DbNull.Value - c#

后端 未结 5 618
夕颜
夕颜 2021-01-01 20:32

What are the benefits of using the c# method DataRow.IsNull to determine a null value over checking if the row equals DbNull.value?

if(ds.Tables[0].Rows[0].I         


        
5条回答
  •  無奈伤痛
    2021-01-01 21:21

    DBNull.Value != null

    DBNull.Value stands for a column having the value . Pop open a table and return some rows, see if any column in any row contains the (ctrl 0) value. If you see one that is equivalent to DBNull.Value.

    if you set a value to null or DBNull.Value then you will want to use IsNull(). That returns true if the value is either null or DBNull.Value. Consider the following:

    row["myCol"] = null;

    row["myCol"] = DBNull.Value

    if (row["myCol"] == DBNull.Value) //returns true

    if (row["myCol"] == null) //returns false

    if (row.IsNull("myCol")) //returns true

    The point is if you are just checking for null or DBNull.Value use IsNull, if you are only checking for DBNull.Value explicitly say so and use that.

提交回复
热议问题