数据库查询比较菜鸟的问题!Datatimepicker 日期的问题(100)

  • 主题发起人 主题发起人 jinnys
  • 开始时间 开始时间
J

jinnys

Unregistered / Unconfirmed
GUEST, unregistred user!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SqlStr:='select * from Maintable where date between '+'datetostr(datetimerpicker2.date) and datetostr(datetimerpicker3.date)'; DBQuery.Close; DBQuery.SQL.Clear; DBQuery.Sql.Add(sqlstr); DBQuery.Active:=true;~~~~~~~~~~~~~~~~~~~~~~~~~~~~编译能过,运行的时候报错。 "undefine function 'datetostr' in expression"帮忙看看哪里出问题了,谢谢!!
 
尝试着改为~~~~~~~~~~~~~~~~~~~~~~~~~~~~var T1,T2:string; T1 := DateToStr(DateTimePicker2.Date); T2 := DateToStr(DateTimePicker3.Date); SqlStr:='select * from Maintable where BETWEEN '''+T1+''' and '''+T2+''''; DBQuery.Close; DBQuery.SQL.Clear; DBQuery.Sql.Add(sqlstr); DBQuery.Active:=true;~~~~~~~~~~~~~~~~~~~~~~~~~~~~报错变成类型不匹配!
 
参数形式: DBQuery.Close; DBQuery.SQL.Text := 'select * from Maintable where date between :StartDate and :EndDate'; DBQuery.Parameters.ParamByName('StartDate').Value := datetimerpicker2.date; DBQuery.Parameters.ParamByName('EndDate').Value := datetimerpicker3.date; DBQuery.Active:=true;
 
hi smlabc,用这种方式还是报错,类型不匹配!date 字段 在数据库中是日期型的数据库是access数据库
 
终于通过了,代码是下面这个 T1 := DateToStr(DateTimePicker2.Date); T2 := DateToStr(DateTimePicker3.Date); SqlStr:='select * from Maintable where date BETWEEN DateValue('''+T1+''') AND DateValue('''+T2+''') '; DBQuery.Close; DBQuery.SQL.Clear; DBQuery.Sql.Add(sqlstr); DBQuery.Active:=true;谢谢
 
SqlStr:='select * from Maintable where date between ' + datetostr(datetimerpicker2.date) + ' and ' + datetostr(datetimerpicker3.date);
 
晕啊SqlStr:='select * from Maintable where date between '+'datetostr(datetimerpicker2.date) and datetostr(datetimerpicker3.date)';----你把datetostr...这些都放到引号里面去了,那就是SQL的一部分了,还怎么执行!楼上正解
 
access数据库的日期变量要加 ‘#’
 
后退
顶部