请高手指点下,我在access数据库中用如下的语句查询,可以得到结果
Select *
from tOldCard
where whenPrepaid>=#2010-04-01# And whenPrepaid<=#2010-04-30 23:59:59# And whoPrepaid='admin';可是在delphi中代码也这样写就报错。
'不正常地定义参数对象。提供了不一致或不完整的信息。'delphi代码是:
procedure TFrmMain.BBtnSelectClick(Sender: TObject);
var
  DateTimeBegin,DateTimeEnd : String;
  strOper : String;
  sSQL : String;
  i : integer;
begin
  DateTimeBegin := DateToStr(DateTimePickerBegin.Date)+' 00:00:00';
  DateTimeEnd := DateToStr(DateTimePickerEnd.Date) + ' 23:59:59';
  strOper := ComboBoxOper.Text;
  i := CompareDateTime(DateTimePickerBegin.Date,DateTimePickerEnd.Date);
  if i > 0 then
  begin
    Application.MessageBox('开始时间不能晚于结束时间,请重新选择开始时间!',PChar(Application.Title),mb_IconError);
    DateTimePickerBegin.SetFocus;
  end;
  sSQL := 'select * from tOldCard ';
  sSQL := sSQL + ' where whenPrepaid >= '''+DateTimeBegin+''' and whenPrepaid <= '''+DateTimeEnd+''' ';
  if ComboBoxOper.Text<> '' then
  begin
    sSQL := sSQL + ' and whoPrepaid= '''+ ComboBoxOper.Text +''' ';
  end;
  SelectAllPrepaidCard(ADOQuery2,DBGrid2,sSQL);//SelectAllPrepaidCard自定义的一个函数
end;

解决方案 »

  1.   

      Strutils
      sSQL := sSQL + ' where whenPrepaid >=' +Quotedstr(DateTimeBegin)+' and    whenPrepaid   <= '+Quotedstr(DateTimeEnd);
      if ComboBoxOper.Text<> '' then
      begin
      sSQL := sSQL + ' and whoPrepaid='+QuotedStr(Combobox1.Text);
      end;
      

  2.   


      sSQL := sSQL + ' where whenPrepaid >#=' +DateTimeBegin+'# and whenPrepaid <=# '+DateTimeEnd+'#';
      

  3.   

     自己后来无意中解决了,SQL语句没有错的,好象Access不支持对对具体的时间查询,
    比如只能查询2010-05-02, 而不能这样写2010-05-02 09:30:30。
      

  4.   


    whenPrepaid >= #' +DateTimeBegin+'#