Venkat Venkat - 1 year ago 82
C# Question

Parsing a DBNULL value into double

I use the following line to convert the

value into double.


If the datarow is
,I am getting the following exception

'double.Parse(Convert.ToString(data))' threw an exception of type 'System.FormatException'

How to handle this one without using

Ian Ian
Answer Source

Another alternative would be to check if the datarow is DBNull:

double d = datarow is DBNull ? 0 : double.Parse(Convert.ToString(datarow));

This way, you do not need to check for DBNull.Value