将DBNULL值解析为double [英] Parsing a DBNULL value into double
本文介绍了将DBNULL值解析为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下行将datarow
值转换为双精度值.
I use the following line to convert the datarow
value into double.
double.parse(Convert.ToString(datarow));
如果datarow
是DBNULL
,则出现以下异常:
If the datarow
is DBNULL
, I am getting the following exception:
'double.Parse(Convert.ToString(data))'引发了类型为'System.FormatException'
如何在不使用tryparse.
推荐答案
另一种方法是检查datarow
是否为DBNull
:
Another alternative would be to check if the datarow
is DBNull
:
double d = datarow is DBNull ? 0 : double.Parse(Convert.ToString(datarow));
这样,您无需检查DBNull.Value
这篇关于将DBNULL值解析为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文