I am posting a query first time here, So, Please ignore my formatting.
I am trying to update my .accdb file using update command, but result of oledbcommand.executeNonQuery() is 0 hence result is not updating in the database.
Though I am receiving no errors.
Here is what I am doing.
string vsql = string.Format("UPDATE DefTask_List SET [Action]=@Action WHERE [SNo]=@SNo");
vcom.Parameters.AddWithValue("@SNo", row.Cells[0].Value.ToString());
vcom.Parameters.AddWithValue("@Action", comboBox1.Text);
OleDbCommand vcom = new OleDbCommand(vsql, vcon);
vcon.Open();
int k = vcom.ExecuteNonQuery();
vcom.Dispose();
vcon.Close();
Please note that SNo is an autonumber in my .accdb file also with the same way I am inserting and deleting data but that is working fine.
OleDbCommanddoesn't support named parameters. The only matter is their orders.From
OleDbCommand.ParameterspropertyThat's why your first
@ActioninOleDbCommandmatches with@SNoin yourAddWithValueand@SNomatches with your@Actionin yourAddWithValue.Since probably you don't have a data like this, there will be no update operation.
Switch your parameter orders and use
.Addmethod which is recommended instead ofAddWithValue. It may generate unexpected results. Read;AddWithValue()already?Also use
usingstatement to dispose yourOleDbConnectionandOleDbCommandinstead of calling.Dispose()and.Close()methods manually.