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....
Loading
Mahesh DeoPosted Nov 27, 2008, 2:31 AM
Blocked AccountPosted Nov 27, 2008, 1:33 AM
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.