我正在使用以下代码更新我的表格:
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/