更新保存在错误的列中



我正在开发winforms应用程序,并尝试保存数据以在单击按钮时访问数据库。我正在使用更新方法(这不是我第一次使用它(,但是由于某种原因,当我保存数据时,保存在数据库中的值保存错误。 有人可以帮我指出我做错了什么或是否有错误吗?

string cb = "UPDATE Config SET features = @features, pricecost = @pricecost, price1 = @price1, tax = @tax, margem = @margem, price = @price, barcode = @barcode WHERE Code = @code";
cmd = new OleDbCommand(cb, con);
cmd.Parameters.Add("@features", OleDbType.VarChar).Value = txtFeatures.Text;
cmd.Parameters.Add("@price", OleDbType.VarChar).Value = txt_Price.Text;
cmd.Parameters.Add("@price1", OleDbType.VarChar).Value = txt_pricewithouttax.Text;
cmd.Parameters.Add("@margem", OleDbType.VarChar).Value = txt_margem.Text;
cmd.Parameters.Add("@pricecost", OleDbType.VarChar).Value = txt_pricecost.Text;
cmd.Parameters.Add("@tax", OleDbType.VarChar).Value = txt_tax.Text;
cmd.Parameters.Add("@barcode", OleDbType.VarChar).Value = txtBarcode.Text;
cmd.Parameters.Add("@code", OleDbType.VarChar).Value = txtCode.Text;

例如,txt_Price.Text 保存在@price1和txt_margem中。文本保存在@price...

我能做些什么来解决这个问题?

谢谢

您正在使用 OleDB 连接到 Access,即所谓的"Microsoft Jet"。它以根本不匹配参数名称而闻名,而是按序号进行。

您需要按照命令文本中显示的顺序完全按照参数的顺序添加参数,并且不能像在 SQL Server 中那样将同一参数使用两次。

注意你的数据类型,存储价格,因为varchar正在找麻烦。

最新更新