Click here to Skip to main content
15,921,548 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends......

My Problem is

i have retrieved some value from table and loaded it into datatable , after this i have set it as a datasource to datagridview.

Now my Problem is i want to replace a value from 0.00 to ABC in some column (Amount column) when i edit it and then i leave it, Datagridview throws Exception System Exception it's not valid value for decimal because datatype of column in database is decimal.

Can any tell me how can i edit it..
Thanks.
Posted

The problem is you're trying to put text into a field that iwll only have decimal values. Unless you redesign your data structure, there is no solution to your problem.
 
Share this answer
 
Before cascading the number, you need to validate the null and the type of variable as follows:

C#
if (dataRow.IsNull("Amount") or (dataRow["Amount"] as Decimal) != null)
{
  decimal result = Convert.ToDecimal(dataRow["Amount"-);
}
 
Share this answer
 
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900