Click here to Skip to main content
14,330,208 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Before cascading the number, you need to validate the null and the type of variable as follows:

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100