0

i use Database ms Access, and i try to Update some Rows with use parameters like code below

OleDbCommand cmdEditOffline = new OleDbCommand();
cmdEditOffline.CommandText = "UPDATE  TbTransactionToOffline SET Amount = @Amount  WHERE NoRef = @NoRef";
cmdEditOffline.Connection = conn;
cmdEditOffline.Parameters.Add("@Amount", OleDbType.VarChar).Value = txtAmount.Text;
cmdEditOffline.Parameters.Add("@NoRef", OleDbType.VarChar).Value = label1.Text;`
if (conn.State == ConnectionState.Closed) conn.Open();
cmdEditOffline.ExecuteNonQuery();
this.Close();

i hope is that the data is updated in accordance with the parameters, but instead all data is updated. what wrong?

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • You are adding the values in a strange way. See this question: http://stackoverflow.com/questions/5893837/using-parameters-inserting-data-into-access-database – Icepickle Aug 23 '15 at 12:01
  • Access don't support named parameters. Read the remarks section: https://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter(v=vs.110).aspx – Bjørn-Roger Kringsjå Aug 23 '15 at 12:09
  • Actually named parameters are supported. Not sure at what version. MSDN implies Office 2010. https://msdn.microsoft.com/en-us/library/office/ff845220%28v=office.14%29.aspx. Also see https://stackoverflow.com/questions/4857940/ms-access-named-parameters-and-column-names. Regardless, since the op is not using the proper format for named parms, he is using them in order which would work. I would guess his where clause wasn't specific enough. – Mmm Aug 23 '15 at 12:39

1 Answers1

0
cmdEditOffline.Parameters.AddWithValue("@Amount", txtAmount.Text);
cmdEditOffline.Parameters.AddWithValue("@NoRef", label1.Text);
Ali pishkari
  • 532
  • 4
  • 18