Nat Luengnaruemitchai

Geek Blog

  Home  |   Contact  |   Syndication    |   Login
  93 Posts | 0 Stories | 141 Comments | 243 Trackbacks

News

Archives

Post Categories

Blogroll

Why does Microsoft introduce DBNull.Value while it can use null instead?
posted on Friday, April 15, 2005 4:17 AM

Feedback

# re: C# IAQ #3: Why DBNull.Vallue While null Already Exists? 4/16/2005 4:20 PM Luke Stevens
The only substantial difference I've noticed so far is that if you put a null value in SqlParameter, it is as though the parameter did not exist (so it had better be optional), but if you put in DBNull.Value, the parameter is included with a null value.

Oh, and there's the COM interop thing with VT_NULL and VT_EMPTY, which was itself kind of pointless and chaotic.

And have you noticed that contrary to the docs, and contrary to SQL as well, DBNull.Value.Equals(DBNull.Value) is true?

DBNull always seemed pretty pointless to me. I hope someone knows why it's there.

# re: C# IAQ #3: Why DBNull.Vallue While null Already Exists? 4/19/2005 3:07 PM Jim Bolla
Because value types such as int are not nullable.

# re: C# IAQ #3: Why DBNull.Vallue While null Already Exists? 4/19/2005 3:23 PM Nat
But you can use "null" can't you?

# re: C# IAQ #3: Why DBNull.Vallue While null Already Exists? 5/25/2006 5:09 PM Squeezles
Because Microsoft sucks eggs. They wrote methods like getString() that throw exceptions if they encounter null values. Why not box it in an Integer object instead of making me write tons of extra code? I just extended the reader class and wrote methods that use boxing types.

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 2 and 3 and type the answer here: