query查询某时间段内的记录,可是运行时有误,请高手进来看看呀,(有源码)
procedure TForm5.BitBtn1Click(Sender: TObject);
var q:TQuery;
s1,s2:string; //起止时间
d1,d2:double; //起止时间
begin
//得到用户选择的起止时间
s1:=combobox1.Text+combobox2.Text+combobox3.Text;
s2:=combobox4.Text+combobox5.Text+combobox6.Text;
d1:=strtodate(s1);
d2:=strtodate(s2);
if form1.RadioButton1.Checked=True then //查询固定件
begin
form1.Query2.SQL.Clear;
form1.Query2.SQL.Add('select * from 出件登记表 where 日期>:d1 and 日期<:d2');
form1.Query2.Open;
//统计所有的记录条数
q:=TQuery.Create(nil);
q.DatabaseName:='hm';
q.SQL.Clear;
q.SQL.Add('select count(*) as Row_count from 出件登记表 where 日期>:d1 and 日期<:d2');
q.Open;
form1.edit7.Text:=q.fieldbyname('Row_count').AsString;
//统计所有记录的总金额
q.SQL.Clear;
q.SQL.Add('select sum(总金额) as Row_count from 出件登记表 where 日期>:d1 and 日期<:d2');
q.Open;
form1.edit8.Text:=q.fieldbyname('Row_count').AsString;
q.Free;
end
else //查询活动件
begin
form1.query2.SQL.Clear;
form1.query2.SQL.Add('select * from 活动件登记表 where 日期>:d1 and 日期<:d2');
form1.query2.Open;
//统计所有的记录条数
q:=TQuery.Create(nil);
q.DatabaseName:='hm';
q.SQL.Clear;
q.SQL.Add('select count(*) as Row_count from 活动件登记表 where 日期>:d1 and 日期<:d2');
q.Open;
form1.edit7.Text:=q.fieldbyname('Row_count').AsString;
//统计所有记录的总金额
q.SQL.Clear;
q.SQL.Add('select sum(总金额) as Row_count from 活动件登记表 where 日期>:d1 and 日期<:d2');
q.Open;
form1.edit8.Text:=q.fieldbyname('Row_count').AsString;
q.Free;
end;
form5.Close;
end;
运行时显示如下错误:
‘200511’is not a valid date