日期:2014-05-19  浏览次数:20460 次

关于日期范围查询的问题 急
string   sqlstr   =   "select   *   from   表   where   字段1   between   DateValue( '   text1.Text   ')   and   DateValue( '   text2.Text   ')     order   by   字段1   desc ";
运行后说DateValue不是有效的函数,我用的是c#2005中的ASP.NET   请问应该如何修改.谢谢!!!!


------解决方案--------------------
string sqlstr = "select * from 表 where 字段1 between ' "+
DateTime.Parse(text1.Text).ToString( "yyyy-MM-dd ")+ " ' and ' "+
DateTime.Parse(text2.Text).ToString( "yyyy-MM-dd ")+ " ' order by 字段1 desc ";

SQL Server会自动把字符串转换为(T-SQL语言的)DateTime再比较。