I have tried almost everything to insert the current date and time in to a MS Access database using C# and nothing seems to work.
The table structure looks like
ID (primary key)
Est_ID (number)
saveName (text)
userName (text)
timestamp (date/time)
The code looks like this:
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
DateTime today = DateTime.Today;
DateTime time = DateTime.Now;
string name = Request.Form["saveName"];
string my_query = "INSERT INTO TABLENAME (userName, Est_id, saveName, timestamp) VALUES (@userName, @Est_id, @saveName, @timestamp)";
OleDbCommand cmd = new OleDbCommand(my_query, conn);
cmd.Parameters.AddWithValue("@userName", userName);
cmd.Parameters.AddWithValue("@Est_id", est_index);
cmd.Parameters.AddWithValue("@saveName", name);
cmd.Parameters.AddWithValue("@timestamp", time);
cmd.ExecuteNonQuery();
I have tried formatting. I added # but nothing seems to work. This is really frustrating since I have spent more than a day now getting this to work. What am I doing wrong?