2
Answers

reading null values in dataset

monika

monika

15y
7.3k
1
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....
Answers (2)