急,取两个日期之间的所有数据
//传日期差的参数
int Days =Convert.ToInt32(Request.QueryString[ "Days "].Trim());
//利用日期差的参数生成开始时间
string StartTime=System.DateTime.Now.AddDays(-Days).ToString( "yyyy-MM-dd ");
//取系统当前为结束时间
string EndTime=System.DateTime .Now.ToString ( "yyyy-MM-dd ");
//SQL语句
string sqlstr = "select * from Article where PublishTime BETWEEN StartTime AND EndTime order by PublishTime desc ";
sql语句执行老是出错。
我检查时,发现开始日期和结束日期都是正确的。
以上sql语句如果改成
string sqlstr = "select * from Article where PublishTime BETWEEN '2007-8-9 'AND '2007-8-11 'order by PublishTime desc ";
可以正确执行。
请各位大侠指教
------解决方案--------------------string sqlstr = "select * from Article where PublishTime BETWEEN ' " + StartTime + " ' AND
' " + EndTime + " order by PublishTime desc "