现在要做一个预约管理查询窗体,点击查询按钮后,程序能够根据用户设置的条件进行动态查询。在查询时,首先检查查询条件是否为空,如果为空进行提示并退出查询,否则进一步判断是否按时间段查询(checkbox1是否被选中),如果按时间段查询,还需要检查时间段是否合法,即起始时间是否大于终止时间,如果时间段不合法,进行提示并退出查询。查询代码如下:procedure Tyygl.SpeedButton1Click(Sender: TObject);
begin
  if (Trim(ComboBox6.Text)<>'')and(Trim(Edit4.Text)<>'') then
  begin
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      if CheckBox1.Checked = False then
      begin
        SQL.Add('select * from Subs_stat where ');
        SQL.Add(Trim(ComboBox6.Text));
        SQL.Add('=');
        SQL.Add(':a');
      end
      else
      begin
        SQL.Add('Select * from Subs_stat where');
        SQL.Add(Trim(ComboBox6.Text));
        SQL.Add('=');
        SQL.Add(':a');
        SQL.Add('and 预约时间 in (Select 预约时间 from Subs_stat where 预约时间>=:b and 预约时间<= :c)');
        Parameters.ParamByName('b').Value := Int(RzDateTimePicker1.Date)-2 ;
        Parameters.ParamByName('c').Value := Int(RzDateTimePicker2.Date)-2+ 0.9998;
      end;
      Parameters.ParamByName('a').value := Trim(Edit4.Text);
      Open;
    end;
    if ADOQuery1.RecordCount >0 then
      DataSource1.DataSet := ADOQuery1;
  end;
end;现在语法检查没有错误,运行后按时间段查询结果为空,与实际不符的。
请朋友们帮忙!尽快。谢谢

解决方案 »

  1.   


    Parameters.ParamByName('b').Value := Int(RzDateTimePicker1.Date)-2 ;
    Parameters.ParamByName('c').Value := Int(RzDateTimePicker2.Date)-2+ 0.9998;把这两句赋值改成下面这样试试  dt1:=self.RzDateTimePicker1.Date-2;
      dt2:=self.RzDateTimePicker2.Date-2+0.9998;
      DecodeDate(dt1,year1,mon1,day1);
      DecodeDate(dt2,year2,mon2,day2);
      dt1:=encodedatetime(year1,mon1,day1,0,0,0,0);
      dt2:=EncodeDateTime(year2,mon2,day2,23,59,59,999);
      Parameters.ParamByName('b').Value := dt1 ;
      Parameters.ParamByName('c').Value := dt2;