DateTime "data type mismatch" in C# and Access

I'm using C# WinForms as an interface to an Access database. I have two fields of the type date/time in my database. In my code, I've checked everywhere to see that the variables I'm trying to enter into the DB are DateTime variables. The following is my relavant code:



addNewExpert.Parameters["ID"].Value = newExpert.ID;
addNewExpert.Parameters["FN"].Value = newExpert.FirstName;
addNewExpert.Parameters["LN"].Value = newExpert.LastName;
addNewExpert.Parameters["GDiv"].Value = newExpert.GroupDivision;
addNewExpert.Parameters["Dept"].Value = newExpert.Department;
addNewExpert.Parameters["MT"].Value = newExpert.MediaTraining;
addNewExpert.Parameters["Vet"].Value = newExpert.Vetted;
addNewExpert.Parameters["VetDate"].Value = newExpert.VettedDate;
addNewExpert.Parameters["VetBy"].Value = newExpert.VettedBy;
addNewExpert.Parameters["CompSent"].Value = newExpert.ComplianceSent;
addNewExpert.Parameters["CompDate"].Value = newExpert.ComplianceDate;
addNewExpert.Parameters["AName"].Value = newExpert.AsstName;
addNewExpert.Parameters["ContMeth"].Value = newExpert.ContactMethod;
addNewExpert.Parameters["Cmts"].Value = newExpert.Comments;

addNewExpert.CommandText = "INSERT INTO tblExperts VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

temp = addNewExpert.ExecuteNonQuery();

It's pretty straightforward, but I can't seem to get past the "Data type mismatch in criteria expression" error. I'm using a DateTimePicker object to retrieve the data from the user. My code associated with that is:



currentExpert.VettedDate = dtp_VettedDate.Value;
currentExpert.ComplianceDate = dtp_ComplianceDate.Value;

Any ideas as to where I'm going wrong?

Thanks!

[2254 byte] By [mustangchik83] at [2007-12-16]
# 1

Alright, I finally solved my own problem by dinking around with C# until I found it. Anyway, if anyone else ever runs into this problem, you need to use:

addNewExpert.Parameters["VetDate"].Value = newExpert.VettedDate.ToOADate();

That ToOADate() thing is the key.

mustangchik83 at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2

Yes, that's the point. I had the same problem and don't found a solution anywhere.

Very thanks.

fjcardoso at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified