0

I can't Figure out what is wrong with the query, but it is not updating any value in the Table

string qry = "UPDATE Stock SET  Itemname=@n,Unit=@u,Price=@p,Tax=@t,Balance=@b,Status=@s Where Sid=@sid";
OleDbCommand ocmd = new OleDbCommand(qry,BBC);
ocmd.Parameters.AddWithValue("@n", name);
ocmd.Parameters.AddWithValue("@u", unit);
ocmd.Parameters.AddWithValue("@p", price);
ocmd.Parameters.AddWithValue("@t", tax);
ocmd.Parameters.AddWithValue("@b", balance);
ocmd.Parameters.AddWithValue("@s", status);
ocmd.Parameters.AddWithValue("@sid", sid);
ocmd.ExecuteNonQuery();

Price,Tax and Balance are Decimal values.

I did debug and its working fine but just not updating the value.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
Shelly
  • 301
  • 5
  • 18

2 Answers2

0

set the type of each parameter and execute the query.

List<OleDbParameter> paramList = new List<OleDbParameter>();

OleDbParameter param = new OleDbParameter("@param", OleDbType.TypeName);

param.Value = value;

paramList.Add(param);

ocmd.Parameters.AddRange(paramArray);
Ghost Developer
  • 1,283
  • 1
  • 10
  • 18
0

I think this will do it for you.

string ConnString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\your_path_here\test.accdb";
using(OleDbConnection conn = new OleDbConnection(ConnString ))
using(OleDbCommand cmd = conn.CreateCommand())
{
   cmd.CommandText = @ "UPDATE Stock SET  Itemname=@n,Unit=@u,Price=@p,Tax=@t,Balance=@b,Status=@s Where Sid=@sid";

   cmd.Parameters.AddWithValue("@n", txtItemName.Text);
   cmd.Parameters.AddWithValue("@u", txtUnit.Text);
   cmd.Parameters.AddWithValue("@p", Convert.ToDecimal(txtPrice.Text));
   cmd.Parameters.AddWithValue("@t", Convert.ToDecimal(txtTax.Text));
   cmd.Parameters.AddWithValue("@b", Convert.ToDecimal(txtBalance.Text));
   cmd.Parameters.AddWithValue("@s", txtStatus.Text);
   cmd.Parameters.AddWithValue("@sid", txtSID.Text);

   conn.Open();
   int rowsAffected = cmd.ExecuteNonQuery();
   conn.Close();
}
ASH
  • 20,759
  • 19
  • 87
  • 200