Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 输入字符串的格式不正确asp.net_C#_Asp.net - Fatal编程技术网

C# 输入字符串的格式不正确asp.net

C# 输入字符串的格式不正确asp.net,c#,asp.net,C#,Asp.net,我得到这个错误不知道为什么 这里是代码(注释中的值) protected void FormView1_ItemCommand(object sender, System.Web.UI.WebControls.FormViewCommandEventArgs e) { if (e.CommandName == "Update") { dsServicesTableAdapters.Select_NegotiateTableAda

我得到这个错误不知道为什么

这里是代码(注释中的值)

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
表格

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
,因为它是一个currency-ID。然后您必须修复这个bug。
DropDownList.SelectedValue
在为int-ID时不应为
0.0105

除此之外,如果当前区域性未使用点
作为十进制分隔符,则也会出现异常。然后,您必须使用
不变量区域性
强制使用此分隔符:

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

您正在使用Int32.Parse解析值,如0.0105。正如你所知道的,这不是 一个整数值,因此它将引发异常。还有一件事我可以在这里看到你
正在使用int表示@Currency\u ID int。它也应该是money或decimal。

您如何确定
ddlphipmentye。SelectedValue
为2?可能是
“2”
?(即带有空格)这也适用于所有其他解析调用。你有多确定所有这些都会起作用?还有,这是什么
Int32.Parse(ddlCurrency.SelectedValue),//0.0105
是该字段中的值吗?那你为什么要把它解析成int呢?如果是这样的话,您应该创建验证来处理这类事情,但我猜您希望使用
decimal.Parse
来代替。hi@LasseV.Karlsen我确信在debuggeryes LasseV.Karlsen中没有空格我已经检查过了它是ddlCurrency.SelectedValue thanksBtw,在这里,您可以看到使用具有有意义名称的变量而不是直接从控件传递参数的好理由。这也使得调试更容易。
Currency\u ID
听起来好像是货币表的外键,所以money或decimal是不合适的。价格已经是钱了,但是其他栏目。