Passing DateTime to query, comparing

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi everyone,

I'm trying to write a parameterized query that accepts a DateTime value for
comparison against a DateTime value held in a given row in an UPDATE
operation. If the two DateTime values aren't equal, then the row is not
updated. The DateTime variable passed to the query comes from the same row
that it is later compared to (when the row is downloaded to a DataSet) - so
it should be equal.

I'm using ADO.NET and Jet 4.0

This is the query:

PARAMETERS ..... [edited date] DateTime ....;
......
WHERE editedDate = [edited date]
.......;

and the ADO stuff:

Dim query As OleDbCommand = new OleDbCommand("EXEC myProc")
query.parameters.add("editd date",date) '// date is a DateTime object
.....
query.ExecuteNonQuery()


However, the comparison always fails, even if the the two times are equal.
Any ideas?

Thanks,

Dave Hagedorn
 
However, the comparison always fails, even if the the two times are equal.
Any ideas?

An Access Date/Time value is stored as a Double Float number, a count
of days and fractions of a day since midnight, December 30, 1899. As
such, it's accurate to a few microseconds - but can only be displayed
or searched to the nearest second.

I'd suggest comparing Format([datefield], "mm/dd/yyyy hh:nn:ss") to
Format([search term], "mm/dd/yyyy hh:nn:ss"), converting both to
strings in the same format.
 
Back
Top