簡體   English   中英

輸入字符串的格式不正確asp.net

[英]Input string was not in a correct format asp.net

我收到此錯誤,不知道為什么...

這是代碼(注釋中的值)。

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

        }
    }

這是我的存儲過程

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

這是我的談判桌

任何想法,為什么我得到此錯誤,盡管我猜有正確的值

Int32.Parse(...)Decimal.Parse(...)引發異常。 我首先看到的是:

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

這顯然不是int所以使用

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

但是,在您的存儲過程中,這似乎也是一個int因為它是貨幣ID。 然后,您必須修復此錯誤。 當它是一個int-ID時, DropDownList.SelectedValue不應為0.0105

除此之外,如果您當前的文化不使用點,您也將獲得例外. 作為小數點分隔符。 然后,您必須使用InvariantCulture強制執行此分隔符:

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

您正在使用Int32.Parse來解析值,例如0.0105。 如您所知,這不是整數值,因此它將引發異常。 正如我在這里看到的,還有一件事,您正在將int用於@Currency_ID int。 它也應該是金錢或十進制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM