I searched in this forum, but it didnt help my solve my problem. Please help me.
This is my code

int intOrderNo = (int) Session["sOrderNo"];
DetailsViewRow row0 = DetailsView1.Rows[0];
string strProductId = row0.Cells[1].Text;
DetailsViewRow row6 = DetailsView1.Rows[6];
string strUnitPrice = row6.Cells[1].Text;
float floUnitPrice = float.(strUnitPrice);
string strQty = DropDownList1.Items[DropDownList1.SelectedIndex].ToString();
int intQty = int.Parse(strQty);

string strSQL = "INSERT INTO ItemTable(bOrderNo, bProductId, bQty, bUnitPrice)"
+ "VALUES (@OrderNo, @ProductId, @Qty, @UnitPrice)";
cmd = new OleDbCommand(strSQL, mDB);
cmd.Parameters.AddWithValue("@OrderNo", intOrderNo);
cmd.Parameters.AddWithValue("@ProductId", strProductId);
cmd.Parameters.AddWithValue("@Qty", intQty);
cmd.Parameters.AddWithValue( "@UnitPrice" , floUnitPrice );
mDB.Open();
cmd.ExecuteNonQuery();
mDB.Close();
Response.Redirect("ShoppingCart.aspx");

But i got an error saying that Input String was not in a correct format. Below is the stack trace


[FormatException: Input string was not in a correct format.]
System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt) +9415395
System.Single.Parse(String s) +23
ProductDetails.BuyBtn_Click(Object sender, EventArgs e) in c:\Users\Administrator\Documents\Visual Studio 2010\WebSites\WebSite4\ProductDetails.aspx.cs:39
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Oh thanks for your input.The error begins at the following line:
float floUnitPrice = float.(strUnitPrice);

If any conversion shoult take pleace, always is recommended to use a try/catch structure to catch any exception and be able to process as expected.

Most of the problems with number conversions came of not testing, with some regex, that the input value is a valid number.

Also, many times is needed to convert the number format from local culture to invariant culture, using the System.Globalization, in order to process smoothly.

Hope this helps

It means your value can NOT be converted to float. Its just not that object to cast.
Set break point, and go to check what kind of value has "strUntitPrice".

strUnitPrice is supposed to be the price of a product.
If float cannot be used, can someone tell me what to use for this?

Right I found the solution to it.
Turns out it was a honest mistake by me >.<
It should have been DetailsViewRow row5 = DetailsView1.Rows[5]; instead

So, to anyone who is having the same problem as me, try to check if the rows where you are reading the values off of is the correct row

And thanks to anyone who replied to thread

Cheers,
FadeTerra

This question has already been answered. Start a new discussion instead.