You are not correctly using the
OleDbCommand
object. Here is a Google Search that will explain how to use it correctly:
c# how to use OleDbCommand[
^].
Also, as mentioned in your last question, you should never put values into the query string. Doing so opens you to
SQL injection attacks[
^].
Here is how to
update using
OleDbCommand
:
cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = $"UPDATE {TableName} SET {ColumName} = @value WHERE ID = @id";
cmd.Parameters.AddWithValue("@id", WhatToInsert);
cmd.Parameters.AddWithValue("@value", UpdatedInfo);
cmd.Connection = connection;
connection.Open();
cmd.ExecuteNonQuery();
{
MessageBox.Show("Update Success!");
cn.Close();`
}