asp.net/C# 中access 数据库 查询时间问题 急!

来源:百度知道 编辑:UC知道 时间:2024/06/21 20:17:52
要查询进3天内发布的商品 这样写
string sql1 = "select * from ProductCX where lei='汽车' and fbsj>"+DateTime.Now.AddDays(-3) +" order by ID desc";
可时间后面会有一个空格 会提示格式错误

怎么解决 十分感谢!急!

string sql1 = "select * from ProductCX where lei='汽车' and fbsj> #" + DateTime.Now.AddDays(-3).ToString() + "# order by ID desc";

Access里的时间用#括起来,比如:
#2009-07-07 12:00:00#
或者
#2009-07-07#

fbsj 掉了单引号

"select * from ProductCX where lei='汽车' and fbsj> '"+DateTime.Now.AddDays(-3).ToString()+"' order by ID desc";