1

我想从 sql server 数据库 2008 R2 中获取浮点数据。

在数据库中有两个字段estimated_amountactual_amount.

起初只estimated-amount填充包含值,并且该actual_amount字段包含NULL.

问题是当我获取数据并解析它显示错误的值时:

System.FormatException 未被用户代码处理 Message=输入字符串的格式不正确。源=mscorlib

我的代码是:

CRM_Doctor_RequestObj.Actual_Amount = float.Parse(Convert.ToString(row["Actual_Amount"]));

请建议我能做什么..

4

2 回答 2

1

从数据库中选择 actual_amount 之类的

SELECT ISNULL((actual_amount),'0.00') FROM TableName

如果 actual_amount 为空,则为 0.00

于 2013-02-04T10:16:40.167 回答
1

少写代码,避免翻译成字符串。您将不得不单独处理 null - 根据row具体情况,它可能支持IsNull/IsDBNull方法,因此它更像:

if(row.IsNull("Actual_Amount"))
   CRM_Doctor_RequestObj.Actual_Amount = null;
else
   CRM_Doctor_RequestObj.Actual_Amount = (float)row["Actual_Amount"];
于 2013-02-04T10:20:36.510 回答