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["Id"] != null) //if (rdr["Id"] != System.DBNull.Value)
{
int x = Convert.ToInt32(rdr["Id"]);
}
}
While I retrieve data from the database using a sql datareader, though there is no value returned if(rdr["Id"] != null) returned true and eventually threw an exception for casting a null as integer.
But, this if I use if (rdr["Id"] != System.DBNull.Value) returns false.
What's the difference between null and System.DBNull.Value?
System.Data, and the other is a special value signifying the lack of a referent. They have nothing to do with each other. Can you elaborate on what you're confused about? Is your real question "why doDataRowsandDataReadersputDBNull.Valueinside of themselves instead ofnull?"null.