If I try to write a datetime to a record in an MS-Access database the easy way, like this
cmd.CommandText = "INSERT INTO [table] ([date]) VALUES (?)";
cmd.Parameters.AddWithValue("?", DateTime.Now);
I get an exception saying "Data type mismatch in criteria expression."
Can anybody tell me why? What goes wrong here?
After a little experimentation, I found that I can make it work if I write
OleDbParameter parm = new OleDbParameter("?", OleDbType.Date);
parm.Value = DateTime.Now;
cmd.Parameters.Add(parm);
but doing it like this seems less neat, less straightforward. Why is this necessary? Am I overlooking something simple?
date
might be a keyword here. TryINSERT INTO table ([date]) VALUES (?)
– Indamine