Parsing a DBNULL value into double

前端 未结 3 1807
后悔当初
后悔当初 2021-01-25 06:17

I use the following line to convert the datarow value into double.

double.parse(Convert.ToString(datarow));

If the datarow

3条回答
  •  星月不相逢
    2021-01-25 06:39

    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

提交回复
热议问题