Reputation: 588
I want to fetch float data from sql server database 2008 R2.
In database there are two fields estimated_amount
and actual_amount
.
At first only estimated-amount
filled contains value, and the actual_amount
field is containing NULL
.
The problem is that when I fetch data and parse the value it shows error:
System.FormatException was unhandled by user code Message=Input string was not in a correct format. Source=mscorlib
My code is :
CRM_Doctor_RequestObj.Actual_Amount = float.Parse(Convert.ToString(row["Actual_Amount"]));
Please suggest what I can do..
Upvotes: 1
Views: 1399
Reputation: 239764
Write less code and avoid translating to string. You will have to deal with the null separately - Depending on what row
is, it may support an IsNull
/IsDBNull
method, so it would be more like:
if(row.IsNull("Actual_Amount"))
CRM_Doctor_RequestObj.Actual_Amount = null;
else
CRM_Doctor_RequestObj.Actual_Amount = (float)row["Actual_Amount"];
Upvotes: 1
Reputation: 1526
From database select actual_amount like
SELECT ISNULL((actual_amount),'0.00') FROM TableName
If actual_amount is null then it gives 0.00
Upvotes: 1