What is the difference between null and System.DBNull.Value?

后端 未结 6 600
忘了有多久
忘了有多久 2020-11-22 11:02

Is there any difference between null and System.DBNull.Value? If yes, what is it?

I noticed this behavior now -

while (rdr.Read())
{
    if (rdr[\"I         


        
6条回答
  •  攒了一身酷
    2020-11-22 11:21

    DataRow has a method that is called IsNull() that you can use to test the column if it has a null value - regarding to the null as it's seen by the database.

    DataRow["col"]==null will allways be false.

    use

    DataRow r;
    if (r.IsNull("col")) ...
    

    instead.

提交回复
热议问题