我用query条件查询,stringgrid为什么不能显示出根据条件查询出的记录?
在EDIT中输入编号,
根据编号进行查询,如果输入的编号存在就在stringgrid显示出来。否则显示没有
我的代码是:
procedure form1.button1click()
var
i,j:integer;
begin
with query1 do
begin
close;
sql.clear;
sql.add('select * from biao');
sql.add('where 编号=:mid');
parambyname('mid').asstring:=edit1.text;
open;
stringgrid1.rowcount:=query1.recordcount;
stringgrid1.colcount:=query1.fieldcount;
if table1.findkey([edit1.text]) then //table1 是biao
begin
j:=0;
while not eof do begin
for i:=0 to stringgrid1.colcount-1 do
stringgrid1.cells[i,j]:=query1.fields[i].asstring;
inc(j);
query1.next;
end;
end
else
showmessage('no find');
end;
end;
程序运行的问题是:
输入编号后,不能在stringgrid中显示出与编号相符合的记录。请问错在哪里?