AbstractI see a lot on forums the question being asked about DBNull, and why it may cause problems when you read values from a reader, or try to assign it to a value type. This article delves into DBNull more explicitly and shows the differences between various objects.

The DBNull class is a special situation when it comes to
working with the ADO.NET framework, and even though it's mostly
straightforward, I still see a lot of confusion about how it can be used. So I
am writing this in hopes that this may alleviate someone's problems in the
future.

Title:
Datetime & DBNull Reply
Name:
Brian
Date:
2007-11-10 11:29:55 PM
Comment: You can't cast directly; DBNULL and DateTIme are two separate object types, and you can't cast one to the other. However, in an ADO.NET datarow object, the underlying value is object, which could accept both. However, if the field is not null, then you can't assign a null value to it. It all depends on your code.

Title:
Datetime&DBnull
Name:
Erick
Date:
2007-11-09 6:49:21 AM
Comment: When I assigned DBNull.Value to System.Datetime, it raised a exception. Can I set a Datetime field of the database to null by using DBNull.Value in ADO.net?