gpt4 book ai didi

c# - System.Data.SqlClient.SqlException nvarchar 为 float

转载 作者:行者123 更新时间:2023-11-29 07:18:01 24 4
gpt4 key购买 nike

我正在使用以下代码更新我的表格:

 private void AddToQuotation()
{
con.Open();
cmd = new SqlCommand(@"update JobQuotations
set quo_discount = @discount
, quo_unitPrice = @unitPrice
, quo_TotalAmount = @totalAmount
, quo_finishing = @finishing
where quo_custname = @customername
and quo_verified = 'Yes'", con);

cmd.Parameters.AddWithValue("@customername",DropDownList3.SelectedItem.Value.ToString());
cmd.Parameters.AddWithValue("@discount",txtDisc.Text);
cmd.Parameters.AddWithValue("@unitPrice",txtUnitPrice.Text);

cmd.Parameters.AddWithValue("@finishing",txtFinishing.Text);
cmd.Parameters.AddWithValue("@totalAmount",lblTotalAmount.Text);
cmd.ExecuteNonQuery();
con.Close();
string script = "alert(\"Functioning!\");";

ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
}

我不断收到此错误:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Error converting data type nvarchar.

这段代码上次对我有用。我不知道发生了什么。

最佳答案

我建议您使用SqlDbType并将每个参数放入数据库中相应的类型,如下所示:

cmd.Parameters.Add (new SqlParameter("@unitPrice", SqlDbType.Float).Value = txtUnitPrice.Text ;

cmd.Parameters.AddWithValue("@unitPrice", SqlDbType.Float).Value = txtUnitPrice.Text;

关于c# - System.Data.SqlClient.SqlException nvarchar 为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37184211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com