Which event is your foreach loop occurring?
Main Topics
Browse All TopicsI'm trying to update a dataview row. The column is a decimal, and I want to format it, but I get the following error:
Input string was not in a correct format.Couldn't store <$25,000> in NEWRESERVE Column. Expected type is Decimal.
the variable previousReserve is a decimal, and the column NewReserve in the dataview is a decimal. I tried casting to a string, but that did not work.
My code:
foreach (DataRowView drv in dv)
{
drv["NewReserve"] = string.Format("{0:'$'#,###
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
After I do that loop through the dataview, i do:
dg.DataSource = dv;
dg.DataBind();
I guess I'm just going to have to create a datatable and in the dataview loop assign the dataview columns to the datatable columns and then bind the datatable to the datagrid. The datatable columns will be string, so I won't get the conflict....was hoping for a way to do it inside the dataview row loop...
Business Accounts
Answer for Membership
by: MRomaniPosted on 2009-11-03 at 13:12:59ID: 25733723
The reason you got the error is that newreserve is expecting a decimal, and what you are passing it (string.Format("{0:'$'#,## #,#0}", previousReserve) ) is not a decimal, its a string.