I want to decrease my urunadedi
value in an Access database. I have the following code:
cmd2.Connection = con;
cmd2.Parameters.AddWithValue(\"@uruni
Microsoft OLEDB ignores parameter names and only pays attention to the order in which the parameters appear in the CommandText. So, for
cmd2.CommandText = @"UPDATE Table1
SET urunadedi=urunadedi-@hesaplam
WHERE urunadi=@urunid";
we need to add the @hesaplam
parameter first since it appears first in the CommandText
cmd2.Parameters.AddWithValue("@hesaplam", Convert.ToInt64(textBox2.Text));
cmd2.Parameters.AddWithValue("@urunid", Convert.ToInt64(textBox1.Text));
Note also that because the OLEDB parameter names are ignored it is quite common to see the question mark (?
) being used as the parameter placeholder:
cmd2.CommandText = @"UPDATE Table1
SET urunadedi=urunadedi-?
WHERE urunadi=?";
cmd2.Parameters.AddWithValue("?", Convert.ToInt64(textBox2.Text)); // @hesaplam
cmd2.Parameters.AddWithValue("?", Convert.ToInt64(textBox1.Text)); // @urunid