I have to read a database using dataset. My database has some null values.
My code is working fine when there is a value in the database. But when there is a null value in the database, dataset throws an exception.
I have to read null value in a variable. I have tried this....
if (dr["value"] != DBNull.Value)
{
abc = Convert.ToDouble(dr["value"]);
MessageBox.Show("value is:" + abc.ToString());
}
else
{
abc=null;
MessageBox.Show("value is:" + abc.ToString());
}
But it gives an error that null can not be assigned to a double variable(here abc is a double variable). How can I read a null value in a variable.
Can anybody guide me....
Reading null values in dataset
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Blocked AccountRank #403 · 6.2K reputationPosted Nov 26, 2008, 8:33 PM EST
Hi Monika,
If u know that else part executes when null value comes.
then u can do that as follow, in the else part.
string
abc = ""; MessageBox.Show("value is:" + abc);another work u can do , u can set any default value in the field which contains the null value by using the case statement in the stored procedure and check in the page.
Mahesh Deo11 reputationPosted Nov 26, 2008, 9:31 PM EST