Milliseconds using ADO.NET and Microsoft Access database

  • Thread starter Thread starter Lourenço Teodoro
  • Start date Start date
L

Lourenço Teodoro

I would like to know how I would have to write aquery to get data from an
Access database specifying milliseconds in the date. Below is an example of
what I am trying to do:

SELECT * FROM MyTable WHERE timestamp > #2004-04-22 10:00:00# - No
milliseconds, works fine.
SELECT * FROM MyTable WHERE timestamp > #2004-04-22 10:00:00.000.020# -
Generates an exception with the following message: "Syntax error in date in
query expression 'timestamp > #2004-04-22 10:00:00.020#'.".

I have tried a lot of different formats, but none of them worked.

This is the source code that I am using for tests:

IDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\\test.mdb;Persist Security Info=False");
con.Open();
IDbCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM MyTable WHERE timestamp > #2004-04-22
10:00:00.000#";
try{
IDataReader reader = cmd.ExecuteReader();
reader.Close();
}
catch(Exception e2){
MessageBox.Show(e2.Message); //always generate this exception with the
message above
}
finally{
if(con!=null && con.State != ConnectionState.Closed)
con.Close();
}


I would really appreciate if anyone could help me with this issue.

Regards,
Lourenço.
 
It seems that JET does not support milliseconds, but if I use the ODBC
provider I am able to make it work.

Lourenço.
 
Back
Top