繁体   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