【发布时间】:2017-08-22 04:47:46
【问题描述】:
我正在开发 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.Text 保存在@price...
我能做些什么来解决这个问题?
谢谢
【问题讨论】:
-
浏览代码并确保您认为与字段匹配的值。这可能是某处的命名不匹配。
-
有时更新语句的列顺序应与您要更新的字段的排列顺序相同。您是否也可以更新您的问题并向我们展示 Config 表的数据库列架构..
-
我不确定用于 Access 的 OLE DB 驱动程序是否正确支持命名参数。按参数在查询中出现的顺序添加参数。或者应用一个具有解决方法的助手,例如精选 in this answer。
-
感谢您的快速帮助...@MethodMan 你是对的...问题是顺序。
标签: c#