between的后面,and的前后都少了空格,即
conditon += " and LastLogin between '" +
Convert.ToDateTime(dateTimePickerFrom.Text) + "' and '" +
Convert.ToDateTime(dateTimePickerTo.Text) + "'";
注:印象中是不需要用Convert.ToDateTime进行转换的
另外当你只是一表查询的时候没必要带表名,即
strSql = "select ID as 用户ID,UserName as
用户名,UserPwd as 用户密码,LastLogin as 最后登录时间 from UserInfo
where 1=1 " + conditon;
date字符串两边加#不是'。好多人遇到过这个奇葩问题,应该是微软的坑。