Posts tagged with c++.net

Insert TimeStamp Into Access Using C#.NET and C++.NET

November 11th, 2009

There’s a rather strange difference between using C#.NET and C++.NET when using a parameter query to insert a TimeStamp into an MS Access database (field type Date/Time).

The following C# code works perfectly.

OleDbCommand cmd = new OleDbCommand();
cmd.Parameters.Add("@login_timestamp", OleDbType.DBTimeStamp).Value = DateTime.Now.ToString();
cmd.CommandText = "insert into myTable values (?)";

However when converting the same code to C++ you cannot just use OleDbType::DBTimeStamp as this results in an error when inserting the data, instead you have to use OleDbType::Date so the code looks like this.

OleDbCommand ^cmd;
cmd=gcnew OleDbCommand();
cmd->Parameters->Add("@login_timestamp", OleDbType::Date)->Value = DateTime::Now;
cmd->CommandText = "insert into myTable values (?)";