数据库是access的mdb数据库,字段 “打单时间”的数据类型是datetime
程序中使用sql语句查询
1、 adoquery1.SQL.Add('select * from table1 where 打单时间=#'+datetostr(date)+'# and 名称='''+wuliao+'''');
那么执行的时候,没有任何记录,即使在数据库中有符合条件的记录也显不出来。
2、 adoquery1.SQL.Add('select * from table1 where 打单时间 between #'+formatdatetime('yy/mm/dd',datetimepicker1.Date)+'# and #'+formatdatetime('yy/mm/dd',datetimepicker2.Date)+'# and 名称='''+wuliao+'''');程序执行的时候,datetimepicker1中输入2004-6-1 datetimepicker2中输入2004-7-31,那么将所有的记录都显示出来,包括2004-6-1以前的数据
后来sql语句改成
adoquery1.SQL.Add('select * from table1 where 打单时间>=#'+datetostr(datetimepicker1.Date)+'# and 打单时间<=#'+datetostr(datetimepicker2.Date)+'# and 名称='''+wuliao+''''); 问题还是一样,恳请高手指点!
程序中使用sql语句查询
1、 adoquery1.SQL.Add('select * from table1 where 打单时间=#'+datetostr(date)+'# and 名称='''+wuliao+'''');
那么执行的时候,没有任何记录,即使在数据库中有符合条件的记录也显不出来。
2、 adoquery1.SQL.Add('select * from table1 where 打单时间 between #'+formatdatetime('yy/mm/dd',datetimepicker1.Date)+'# and #'+formatdatetime('yy/mm/dd',datetimepicker2.Date)+'# and 名称='''+wuliao+'''');程序执行的时候,datetimepicker1中输入2004-6-1 datetimepicker2中输入2004-7-31,那么将所有的记录都显示出来,包括2004-6-1以前的数据
后来sql语句改成
adoquery1.SQL.Add('select * from table1 where 打单时间>=#'+datetostr(datetimepicker1.Date)+'# and 打单时间<=#'+datetostr(datetimepicker2.Date)+'# and 名称='''+wuliao+''''); 问题还是一样,恳请高手指点!
'select * from table1 where 打单时间>= QuotedStr(datetostr(datetimepicker1.Date)) and 打单时间<= QuotedStr(datetostr(datetimepicker2.Date)) and ...
试试看,最好再加上FormatDateTime
你打个断点看看加入的SQL,放在数据库里面执行一下,基本上会发现问题