我正在尝试使用UPDATE
查询更新我的 Access 数据库。但是由于某种原因,它没有更新,也没有给我一个错误,即使它位于try
和catch
中。
using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\ezter\Desktop\BalfakihPOS.mdb"))
{
try
{
OleDbCommand cmd = new OleDbCommand("SELECT COUNT(*) FROM Products WHERE BarCode = @BarCode", con);
cmd.Parameters.AddWithValue("@Code", barcode.Text);
con.Open();
int result = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
if (result >= 1)
{
cmd = new OleDbCommand("UPDATE Products SET Product_Name=@Product_Name, Product_Price=@Product_Price, WholeSale_Price=@WholeSale_Price, " +
"Product_Quantity=@Product_Quantity, Production_Date=@Production_Date, Expire_Date=@Expire_Date, Product_Cate=@Product_Cate, Product_Disc=@Product_Disc WHERE BarCode=@BarCode ", con);
OleDbParameter[] param = new OleDbParameter[9];
param[0] = new OleDbParameter("@BarCode", OleDbType.Integer);
param[0].Value = barcode.Text;
param[1] = new OleDbParameter("@Product_Name", OleDbType.VarChar);
param[1].Value = pnametxt.Text;
param[2] = new OleDbParameter("@Product_Price", OleDbType.Integer);
param[2].Value = price.Text;
param[3] = new OleDbParameter("@WholeSale_Price", OleDbType.Integer);
param[3].Value = wsprice.Text;
param[4] = new OleDbParameter("@Product_Quantity", OleDbType.Integer);
param[4].Value = pqty.Text;
param[5] = new OleDbParameter("@Production_Date", OleDbType.DBDate);
param[5].Value = pdate.Text;
param[6] = new OleDbParameter("@Expire_Date", OleDbType.DBDate);
param[6].Value = expdate.Text;
param[7] = new OleDbParameter("@Product_Cate", OleDbType.VarChar);
param[7].Value = Convert.ToString(catecombo.SelectedItem);
param[8] = new OleDbParameter("@Product_Disc", OleDbType.VarChar);
param[8].Value = pdisc.Text;
con.Open();
cmd.Parameters.AddRange(param);
cmd.ExecuteNonQuery();
}