I have a problem passing a DateTime value to a query as a DbParameter. It seems the time part of the DateTime value gets stripped away.
Here is a sample code in C#:
DbProviderFactory _factory = OleDbFactory.Instance;
DbCommand cmd = _factory.CreateCommand();
cmd.CommandText = "INSERT INTO SomeTable (SomeDateField) VALUES (?)";
DbParameter p = _factory.CreateParameter();
p.ParameterName = ""; // Not necessary
p.Value = DateTime.Now; // assume Time != 00:00:00
p.DbType = DbType.Date; // DateTime and DateTime2 don't work
cmd.Parameters.Add(p);
My problem is that the Date parameter does not seem to reach Access with it's time part and SomeDateField always has 00:00:00 as time.
I don't want to do something like:
cmd.CommandText = "INSERT INTO SomeTable (SomeDateField) VALUES (#" + aDateTimeString + "#)";