if (i<=dm.adoquery2.RecordCount) and (j<=dm.adoquery3.RecordCount)then
begin With dm.adoquery1 DO
begin
Close;
SQL.Clear;
sql.Add('select zbry from x_xmrz where rq=:a and xmmc=:b and cz=:c');
Parameters.ParamByName('a').Value:=FormatDateTime('yyyy-mm-dd',dtp.Date);
Parameters.ParamByName('b').Value:=StringGrid1.Cells[0,j];
Parameters.ParamByName('c').Value:=StringGrid1.Cells[i,0];
Open;
end; if not dm.adoquery1.EOF then
begin
StringGrid1.Cells[i,j]:=dm.ADOQuery1.fieldbyname('zbry').asstring;
end
else
begin
StringGrid1.Cells[i,j]:='无';
end; i:=i+1;
j:=j+1;
end;
begin With dm.adoquery1 DO
begin
Close;
SQL.Clear;
sql.Add('select zbry from x_xmrz where rq=:a and xmmc=:b and cz=:c');
Parameters.ParamByName('a').Value:=FormatDateTime('yyyy-mm-dd',dtp.Date);
Parameters.ParamByName('b').Value:=StringGrid1.Cells[0,j];
Parameters.ParamByName('c').Value:=StringGrid1.Cells[i,0];
Open;
end; if not dm.adoquery1.EOF then
begin
StringGrid1.Cells[i,j]:=dm.ADOQuery1.fieldbyname('zbry').asstring;
end
else
begin
StringGrid1.Cells[i,j]:='无';
end; i:=i+1;
j:=j+1;
end;
if (i<=dm.adoquery2.RecordCount) and (j<=dm.adoquery3.RecordCount)then
begin With dm.adoquery1 DO
begin
Close;
SQL.Clear;
sql.Add('select zbry from x_xmrz where rq=:a and xmmc=:b and cz=:c');
Parameters.ParamByName('a').Value:=FormatDateTime('yyyy-mm-dd',dtp.Date);
Parameters.ParamByName('b').Value:=StringGrid1.Cells[0,j];
Parameters.ParamByName('c').Value:=StringGrid1.Cells[i,0];
Open;
end; if not dm.adoquery1.EOF then
begin
StringGrid1.Cells[i,j]:=dm.ADOQuery1.fieldbyname('zbry').asstring;
end
else
begin
StringGrid1.Cells[i,j]:='无';
end;
dm.adoquery1.next; //加这句 i:=i+1;
j:=j+1;
end;
加的位置已经给出,如上面的代码。
最好再加上这句 dm.adoquery1.first;
在 if not dm.adoquery1.EOF then 上边
但不知道為什麼這樣寫,多次與database交互讀取,效率低
但上面的代码似乎没有作循环
再有,yyyy-mm-dd好像错了,应该是:yyyy-MM-dd
mm好像是分钟的意思还有,你也没有说出错什么了
你咋会写 if not dm.adoquery1.EOF then呢,你是不是想写
while not dm.adoquery1.EOF do啊?