DBTimeStamp - Data type mismatch in criteria expression

  • Thread starter Thread starter jimmy
  • Start date Start date
J

jimmy

Hi,

I'm receiving an exception of "Data type mismatch in criteriaexpression" when trying to store a date and time to a column ofAccess 2002. The default parameter constructor puts the DBTypeas DbDate which stores only the date portion. It needs to bechanged to DbTimeStamp in order to have the time portion stored.It works for my another program but not this time,unfortunately. I'd spent the last 3 days trying to solve thisproblem as the time portion is critical to my application. Whatdid I do wrong? Thanks.

Jimmy
User submitted from AEWNET (http://www.aewnet.com/)
 
Hi Jimmy,

It could work but would be more dependent on the field properties in Access.
Try using OleDbType.Date instead as the type instead. This maps directly to
System.DateTime and does include both date and time values. In Access be sure
your column's data type is Date/Time and you will have no problems related to
types.

Sample:
OleDbCommand cmd = new OleDbCommand("INSERT INTO Table1 (CreatedDate) VALUES
(@CreatedDate)", db);
OleDbParameter p = cmd.Parameters.Add ("@CreatedDate", OleDbType.Date);
p.Value = DateTime.Now;

Cheers,
Steve Goodyear,
Vancouver, BC
 
Back
Top