我正在处理访问但陷入具有日期时间的插入查询。像这些查询对我不起作用。
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');
任何的想法?有什么问题。
这是我在 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();
我也试过这个。
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);
所有其他插入和选择查询工作正常