[英]Syntax error (missing operator) in query expression in C#
string sqlStatement = "select ID, Checkintime, RoomPrice, OrderNo from Orders where RoomType='" + selectedRoom.Key + "' and RoomNumber=" + selectedRoom.Value + " and Checkintime>="+dateOnly+" and CheckinTime<'"+endingTime+"'";
myAccessCommand = new OleDbCommand(sqlStatement, myAccessConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myDataAdapter.Fill(myDataSet, "Orders");
I have syntax error in the SQL statement line but I am not sure what went wrong that caused an syntax exception. 我在SQL语句行中有语法错误,但是我不确定是什么引起了语法异常。
Short fix: change 简短修正:更改
Checkintime>="+dateOnly+"
to 至
Checkintime>='"+dateOnly+"'
(you forgot the tick marks in the first reference to Checkintime
) (您忘记了对Checkintime
的第一次引用中的刻度线)
Much better: Use a parameterized query 更好: 使用参数化查询
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.