Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 21, 2012 06:02 PM by MetalAsp.Net
Member
192 Points
136 Posts
Feb 21, 2012 05:23 PM|LINK
hello,
error is:
my code is:
DataTable cart = new DataTable(); cart = (DataTable)Session["Cart"]; int total=0; int count=cart.Rows.Count; for (int i = 0; i < count; i++) { total += cart.Rows[i]["price"]; } total_amt.InnerHtml = total;
Star
9337 Points
1447 Posts
Feb 21, 2012 05:26 PM|LINK
Make sure every cell of the column "price" contains numeric value..
and do it :
total += int.Parse(cart.Rows[i]["price"]);
All-Star
112032 Points
18231 Posts
Moderator
Feb 21, 2012 05:28 PM|LINK
Try i < count -1 in the loop since it's zero indexed.
Feb 21, 2012 05:33 PM|LINK
price contains $ amount eg $ 4
how would i get only 4 to addd it
Feb 21, 2012 05:40 PM|LINK
string price = cart.Rows[i]["price"].ToString();
total += int.Parse(price.SubString(1, price.Length - 1).Trim());
Feb 21, 2012 06:02 PM|LINK
Use String.Replace() to replace $ with emtpy string.
Vishul
Member
192 Points
136 Posts
error while adding price store in datatable
Feb 21, 2012 05:23 PM|LINK
hello,
error is:
Input string was not in a correct format
my code is:
DataTable cart = new DataTable();
cart = (DataTable)Session["Cart"];
int total=0;
int count=cart.Rows.Count;
for (int i = 0; i < count; i++)
{
total += cart.Rows[i]["price"];
}
total_amt.InnerHtml = total;
me_ritz
Star
9337 Points
1447 Posts
Re: error while adding price store in datatable
Feb 21, 2012 05:26 PM|LINK
Make sure every cell of the column "price" contains numeric value..
and do it :
total += int.Parse(cart.Rows[i]["price"]);
MetalAsp.Net
All-Star
112032 Points
18231 Posts
Moderator
Re: error while adding price store in datatable
Feb 21, 2012 05:28 PM|LINK
Try i < count -1 in the loop since it's zero indexed.
Vishul
Member
192 Points
136 Posts
Re: error while adding price store in datatable
Feb 21, 2012 05:33 PM|LINK
price contains $ amount eg $ 4
how would i get only 4 to addd it
me_ritz
Star
9337 Points
1447 Posts
Re: error while adding price store in datatable
Feb 21, 2012 05:40 PM|LINK
string price = cart.Rows[i]["price"].ToString();
total += int.Parse(price.SubString(1, price.Length - 1).Trim());
MetalAsp.Net
All-Star
112032 Points
18231 Posts
Moderator
Re: error while adding price store in datatable
Feb 21, 2012 06:02 PM|LINK
Use String.Replace() to replace $ with emtpy string.