0

Possible Duplicate:
What is the point of DBNull?

I have recently been working on a number of sections of code that deal with the insertion of Nullable types into a database.

As I'm sure anyone who has dealt with similar code will be aware of the annoyance of constantly writing conditional logic to deal with the insertion of nulls into a database

IE:

MyValue.HasValue ? MyValue.Value : DBNull.Value;
If(MyValue.HasValue, MyValue.Value, DBNull.Value)

Basically I am just wondering if someone here could be kind enough to explain why DBNull.Value exists and why Null simply couldn't be used?

Community
  • 1
  • 1
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243

1 Answers1

0

Here you have one explanation http://codebetter.com/petervanooijen/2004/04/12/system-dbnull-value-null/

If you call ExecuteScalar and you get null, then it means that no data was found in the database, but if you get DBNull that means you found data but the value was actually null.

Peter
  • 37,042
  • 39
  • 142
  • 198