No matter what I try, I can't seem to add entries to my Access DB. I am using Access 2016. I believe my type mismatch problem is with DateTimes, but none of the solutions I have seen have worked.
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.CommandType = CommandType.Text;
foreach (KeyValuePair<string, string> k in queryParams)
{
if (k.Key.Equals("DOB") || k.Key.Equals("dateJoined"))
{
MessageBox.Show("This is: " + k.Key + " " + k.Value);
string temp = "#" + k.Value + "#";
MessageBox.Show(temp);
cmd.Parameters.AddWithValue(k.Key, temp);
}
else
{
cmd.Parameters.AddWithValue(k.Key, k.Value);
}
}
int t = cmd.ExecuteNonQuery();
}
I have tried just adding them like any other parameter. I have tried adding them as DateTime's. I have tried enclosing them in #. I have tried enclosing them in single quotes. I have tried using DateTime.toaDate and adding them as doubles. I have checked the formats, and both the DB and the DateTimePicker use mm/dd/yyyy. All other fields are short texts, and I know those are working because I can insert short texts into other tables fine.