Assigning DB Null values to variables

Database null values cannot be cast, or converted to a local variable. To get around this use the following snippet when assigning the value to the vairable, to first check if the database value is null. dr is the data reader.

String Message = “”;
if (!dr[“Message”].Equals(DBNull.Value)) Message = dr[“Message”].ToString();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: