Ven*_*kat 2 c# sql parsing dbnull formatexception
I use the following line to convert the datarow
value into double.
double.parse(Convert.ToString(datarow));
Run Code Online (Sandbox Code Playgroud)
If the datarow
is DBNULL
, 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 tryparse.
另一种选择是检查datarow
是否DBNull
:
double d = datarow is DBNull ? 0 : double.Parse(Convert.ToString(datarow));
Run Code Online (Sandbox Code Playgroud)
这样,您就不需要检查DBNull.Value