你这里的dt1,dt2是日期类型,而comm.CommandText里调用的是字符串 所以应该将日期转换成字符串类型 如comm.CommandText = "select * from tablename where date>="+strtodate(dt1)+" and addDate<="+strtodate(dt2);
access的时间问题真的很麻烦,试试看吧,不知道行不行 comm.CommandText = "select * from tablename where date>=#"+strtodate(dt1)+"# and addDate<=#"+strtodate(dt2)+"#"; 再不行我也不知道了
我自己来给出正确答案:access的日期时间与sql的不同,上面的语句在sql数据库中能通过,但在access中通不过,正确的语句是:comm.CommandText = "select * from tablename where date between #" +dt1+"# and #"+dt2+"#"; 我也是刚刚经人指点的,大家一起学习学习吧!
所以应该将日期转换成字符串类型
如comm.CommandText = "select * from tablename
where date>="+strtodate(dt1)+" and addDate<="+strtodate(dt2);
comm.CommandText = "select * from tablename
where date>=#"+strtodate(dt1)+"# and addDate<=#"+strtodate(dt2)+"#";
再不行我也不知道了
where date between #" +dt1+"# and #"+dt2+"#";
我也是刚刚经人指点的,大家一起学习学习吧!