I am facing a problem on passing the DateTime.
Now into Access database:
oleDBCommand.CommandText =
"INSERT INTO tblData "([PIC], [Sampling Date]) "VALUES (@PIC, @SamplingDate)";
oleDBCommand.Parameters.Add(new OleDbParameter("@PIC", combobox1.Text));
oleDBCommand.Parameters.Add(new OleDbParameter("@SamplingDate", DateTime.Now));
I tried a lot of methods from the internet like using oleDBType.Date
, DateTime.Now.ToString()
, using AddWithValue.....
And none of it is working.
Note 1: Database setting [Sampling Date] = Data Type: Date/Time (Format - Long Time)
, database was
Note 2: Below code was working but I prefer to using .parameters as it look much more organize and easy to manage.
oleDBCommand.CommandText =
"INSERT INTO tblData ([PIC], [Sampling Date]) " VALUES ('" + combobox1.Text + "', '" + DateTime.Now + "')";