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

标签 c# mysql

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

 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/

相关文章:

c# - 将焦点从一个列表框移动到另一个列表框

MySQL:带条件的隐式连接:删除重复项需要什么样的语句?

mysql - MacOS High Sierra MySQL5.7服务器消失了,无法进行多连接?

mysql - 在 mysql 中搜索序列化数据中的特定字符

MySQL Workbench 创建前向脚本以错误的顺序删除表,违反外键约束

c# - MVC4 cshtml页面函数调用

c# - 加密/混淆文件名

mysql - 如何使用生成的脚本从SQL 2005到MYSQL?

c# - 如何在Azure中创建数据库?

c# - Autofac,解析操作结束