Saturday, May 14, 2005

Difference between null and DBNull.Value

The System.DBNull class is used to represent a null value. It helps the user in identifying the absence of known value. It is widely used in database application. We also use System.DBNull class in COM interop to distinguish between VT_NULL and VT_EMPTY variant. Where VT_NULL is associated with a null object and VT_EMPTY is with DBNull.Value instance.

System.DBNull class differentiates between a null value and uninitialized value. In database application, a null object is a valid value for a field.

And moreover, if we 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

DBNull is never equal to anything. Of DBNull class only one instance can exist as it a singleton class. Sole instance is DBNull.Value.

Comments: Post a Comment

This page is powered by Blogger. Isn't yours?