I'm having trouble inserting a date into access,in access the data type is Date/Time(general date). i want it to insert today's date so i can call it later and work out how many days have passed (i know how to do that using timespan). So can please tell me the correct way of saving the date to access. Thanx
ps. I dont need the time only the date
DateTime dateNow = DateTime.Now;
string connString = (@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|HorseDB.mdb");
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
OleDbCommand cmdSelect = conn.CreateCommand();
cmd.CommandText = @"INSERT INTO [Users] (PaidDate) VALUES (@PaidDate) WHERE [UserId] = @OrderId";
cmd.Parameters.AddWithValue("@PaidDate", dateNow);
cmd.Parameters.AddWithValue("@OrderId", orderId);
cmd.ExecuteNonQuery();
conn.Close();
INSERT
receives a list of columns you want to set values for, adds a new row to the table, and sets the content of the specified columns to the values you provide. It's adding a new row, so what is theWHERE
supposed to do? – Ken White