I am working on access but stuck in insert queries having date time. like these queries doesn’t work for me.
INSERT INTO tbl_fuel_levels([genset_id], [rec_time], [fuel_level],
[grid_electricity], [genset_electricity], [genset_number])
VALUES('001', '#12/12/23 18:46:38+20#', '0', 'T', 'F', '+923468280124');
INSERT INTO tbl_fuel_levels([genset_id], [rec_time], [fuel_level],
[grid_electricity], [genset_electricity], [genset_number])
VALUES('001', #'12/12/23 18:46:38+20'#, '0', 'T', 'F', '+923468280124');
INSERT INTO tbl_fuel_levels([genset_id], [rec_time], [fuel_level],
[grid_electricity], [genset_electricity], [genset_number])
VALUES('001', '12/12/23 18:46:38+20', '0', 'T', 'F', '+923468280124');

Any idea? what could be wrong.
Here is my code in c#:
con = new OleDbConnection(ConnStr);
con.Open();
cmd = con.CreateCommand();
cmd.CommandText = "INSERT INTO tbl_fuel_levels([genset_id], [rec_time],
[fuel_level], [grid_electricity], [genset_electricity], [genset_number])
VALUES('" + genset_id + "', '" + rec_time + "', '" + fuel_level + "', '" +
grid_electricity + "', '" + genset_electricity + "', '" + genset_number + "');";
cmd.ExecuteNonQuery();
I have also tried this.
cmd.CommandText = "INSERT INTO tbl_fuel_levels([genset_id], [rec_time],
[fuel_level], [grid_electricity], [genset_electricity], [genset_number])
VALUES('" + genset_id + "', @rec_t, '" + fuel_level + "', '" + grid_electricity
+ "','" + genset_electricity + "', '" + genset_number + "');";
cmd.Parameters.Add("@rec_t", OleDbType.DBTimeStamp).Value
= DateTime.Parse(rec_time);
All other insert and select queries are working fine
Your
INSERTquery has more than one problem. I copied this version from your comment to DJ:The problems are:
'#12/11/2023 2:46:38 PM#'into the Date/Time fieldrec_time. Discard the single quotes to make that value a Date/Time literal instead of a string:#12/11/2023 2:46:38 PM#'T'into the Yes/No fieldgrid_electricity. UseTruewithout quotes instead.'F'into the Yes/No fieldgenset_electricity. This is the same issue as problem #2. UseFalsewithout quotes.Use Access’ query designer to create a new query. Switch it to SQL View and paste in this statement:
If there are any remaining problems with that statement, work them out in Access before bothering with the
c#code to create the statement.Or better, use the parameters query approach. Maybe you can get that working once you resolve those issues with the Yes/No fields.