View Single Post
  #3 (permalink)  
Old April 16th, 2008, 03:00 AM
samjudson's Avatar
samjudson samjudson is offline
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Value types can not store a null value.

Int32 IntLevel;

and

Int32 IntLevel = 0;

both do the same thing, create a new integer value and set its initial value to 0.

DBNull, is not the same as 'null' - it is a class used by the database providers to signify a Null in a database field. So you are never (ever) going to be able to assign DBNull.Value to an integer variable.

There is a generic type called Nullable<> (or Nullable(Of) in VB.Net) which can be used to store null values as well as value types.

Nullable<Int32> IntLevel = null;

or

Nullable<Int32> IntLevel = 12;

in C# you can abbreviate Nullable<Int32> to int?.

int? IntLevel = null;

/- Sam Judson : Wrox Technical Editor -/