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.
OleDbCommand
doesn't support named parameters. The only matter is their orders.From
OleDbCommand.Parameters
propertyThat's why your first
@Action
inOleDbCommand
matches with@SNo
in yourAddWithValue
and@SNo
matches with your@Action
in yourAddWithValue
.Since probably you don't have a data like this, there will be no update operation.
Switch your parameter orders and use
.Add
method which is recommended instead ofAddWithValue
. It may generate unexpected results. Read;AddWithValue()
already?Also use
using
statement to dispose yourOleDbConnection
andOleDbCommand
instead of calling.Dispose()
and.Close()
methods manually.