简体   繁体   中英

Input string was not in a correct format asp.net

i am getting this error don`t know why...

here is Code (values in comments)..

protected void FormView1_ItemCommand(object sender, System.Web.UI.WebControls.FormViewCommandEventArgs e)
    {

        if (e.CommandName == "Update")
        {

            dsServicesTableAdapters.Select_NegotiateTableAdapter obj = new dsServicesTableAdapters.Select_NegotiateTableAdapter();

      //here i am getting the input string is not in a correct format error
            obj.Insert_Negotiate_New(Int32.Parse(stockid), //1
                Decimal.Parse(txtfobcustomer.Text),  //10
                Decimal.Parse(txtfrieghtcustomer.Text), //10
                Decimal.Parse(txtvanningcustomer.Text), //10
                Decimal.Parse(txtinspectioncustomer.Text), //10
                Decimal.Parse(txttotal_costcustomer.Text), //10
                Int32.Parse(ddlCurrency.SelectedValue), //  0.0105   
                Int32.Parse(ddlcountry.SelectedValue), //5 
                Int32.Parse(customerid),//1
                txtcustomername.Text, // Anglo  
                txtcustomerEmail.Text, // Anglo@computers.com  
                txtcustomer_phone.Text, // 03313752499  
                txtComments.Text, //test
                Int32.Parse(ddlshipmenttye.SelectedValue)); //2

        }
    }

and here is my stored procedure

ALTER PROCEDURE [dbo].[Insert_Negotiate_New]
(

    @stock_ID int,
    @client_FOB_Price money,
    @Client_FrieghtPrice money,
    @Client_Vanning_Price money,
    @Client_Inspection_Price money,
    @Client_Total_Cost money,
    @Currency_ID int,
    @Country_ID int,
    @Customer_ID int,
    @Client_Name varchar(50),
    @Client_Email varchar(50),
    @Client_Phone varchar(50),
    @Client_Comments varchar(3000),
    @ShipmentType int
)
AS
    SET NOCOUNT OFF;


declare @negotiation_ID int
set dateformat dmy


Begin---insert negotiation

SELECT @negotiation_ID=ISNULL(MAX(negtiation_ID),0)+1 FROM negotiate


INSERT INTO negotiate (negtiation_ID,Time_Stamp, stock_ID,client_FOB_Price, Client_FrieghtPrice, Client_Vanning_Price,
 Client_Inspection_Price, Client_Total_Cost, Currency_ID,Country_ID,
  Customer_ID, Client_Name, Client_Email, Client_Phone, Client_Comments, ShipmentType) 
  VALUES (@negotiation_ID,GETDATE(),@stock_ID, @client_FOB_Price, @Client_FrieghtPrice, @Client_Vanning_Price,
   @Client_Inspection_Price, @Client_Total_Cost, @Currency_ID, @Country_ID,@Customer_ID, 
   @Client_Name, @Client_Email, @Client_Phone, @Client_Comments, @ShipmentType);

End

Table

这是我的谈判桌

Any Idea why i am getting this error although i am guessing that there are correct values

Int32.Parse(...) or Decimal.Parse(...) throws the exception. The first and only i see is:

Int32.Parse(ddlCurrency.SelectedValue), //  0.0105   

This is clearly not an int so use

Decimal.Parse(ddlCurrency.SelectedValue), //  0.0105   

However, in your stored-procedure this seems to be also an int because it's a currency-ID. Then you have to fix this bug. The DropDownList.SelectedValue should not be 0.0105 when it's an int-ID.

Apart from that you would also get the exception if your current culture is not using the dot . as decimal separator. Then you have to enforce this separator by using InvariantCulture :

Decimal.Parse(ddlCurrency.SelectedValue, CultureInfo.InvariantCulture)  

you are using Int32.Parse for parsing value like 0.0105. As you know this is not an integer value so it will throw an exception. One more thing as I can see here you are using int for @Currency_ID int. It should be also money or decimal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM