Name
and Password
are reserved keywords in MS Access.
If a reserved word is already in use, you can avoid error messages by surrounding each occurrence of the word with brackets (
[ ]
). However, the best solution is to change the name to a nonreserved word.
You need to use Reg Date
with square brackets like [Reg Date]
also since it has space. Parameterized your Reg Date
and UserName
column values as you did for other columns. Like;
... [Reg Date] = @reg WHERE UserName = @user ...
cmd.Parameters.AddWithValue("@reg", DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@user", comboBox4.SelectedItem.ToString());
Also use using
statement to dispose your OleDbConnection
and OleDbCommand
.
string conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =C:\\Users\\Kalpesh\\Desktop\\Entry.accdb";
using(OleDbConnection cn = new OleDbConnection(conString))
using(OleDbCommand cmd = cn.CreateCommand())
{
// Do your work..
}