I have a SQL statement causing an error within C# on a MS Access database that seems to intermittently work. I think I tracked down the problem, but don't understand the answer or have a solution.
My SQL statement in C# is written as follows:
// note that Start and StartLog are both nullable variables and ProfileID variable is a string
cmd = new OleDbCommand("INSERT INTO shifts(profile_id, start, start_log) " +
"VALUES (@profile_id, @start, @start_log);");
cmd.Parameters.AddWithValue("@profile_id", ProfileID);
cmd.Parameters.AddWithValue("@start", Start.Value);
cmd.Parameters.AddWithValue("@start_log", StartLog.Value);
The shifts
table has the following columns:
profile_id is a string
start is a date/time
start_log is a date_time
I tried to execute the statement with the following data pulled from the debugger:
profile_id -> "16078965744"
start -> {1/10/2015 1:30:00 PM}
start_log -> {1/10/2015 1:23:13 PM}
and got the following exception:
System.DataOleDb.OleDbException: {"Data type mismatch in criteria expression."}
I noticed that if I called ToString() on Start.Value and StartLog.Value as follows it works:
cmd = new OleDbCommand("INSERT INTO shifts(profile_id, start, start_log) " +
"VALUES (@profile_id, @start, @start_log);");
cmd.Parameters.AddWithValue("@profile_id", ProfileID);
cmd.Parameters.AddWithValue("@start", Start.Value.ToString());
cmd.Parameters.AddWithValue("@start_log", StartLog.Value.ToString());
My suspicion is that the problem is related to this SO answer by Steve that the the millisecond part is causing the exception by a call earlier to DateTime.Now.
Anyone have a solution to this or know what the problem is?
I suspect this will solve my problem, but I am a beginner so frankly I am confused by the whole ordeal.
This problem came out of this question here that is unresolved that I am investigating.