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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…