循环错误题(补题)

BarryW 2008-05-03 12:08:14
我也认为原贴太长;俺也没有办法;
为了问题解决性原则:

“for i :=0 to Fields.Count-1 do
StringGrid1.Cells[i,0]:='a'+inttostr(i);

while not eof do begin
StringGrid1.RowCount:=StringGrid1.RowCount+1;
for i :=0 to StringGrid1.ColCount-1 do”


把“while not eof do begin”去掉就可以过滤重复的数据出来了,没有查出原因

但是还有一点小问题:
点第一下Button事件可以出来,再接着点就什么都不出来了;



procedure TForm1.Button4Click(Sender: TObject);
var
s:string;
begin
if trim(edit1.Text)<>'' then begin
if adoquery1.FieldList.IndexOf(edit1.Text)>=0 then begin {-如果ADOQUERY1中有edit1中输入的字段-}
{---提取adoquery1的SQL语-----}
s := UpperCase(adoquery1.sql.Text);
if Pos('WHERE',s)>0 then
s := Copy(s,1,Pos('WHERE',s)-1) else
if Pos('ORDER',s)>0 then
begin
s := Copy(s,1,Pos('ORDER',s)-1);
end;

StringGrid1.ColCount:=0;{这里默认为五列}
StringGrid1.RowCount:=0;{这里默认为五行}

with adoquery2 do begin
while not eof do begin
adolook.Close;
adolook.SQL.Text:=s+' where '+trim(edit1.Text)+'='+QuotedStr(adoquery2.FieldValues[trim(edit1.Text)]);
adolook.open;
if not adolook.IsEmpty then begin

{重复时写StringGrid用作显示}
StringGrid1.ColCount:=Fields.Count;
{--标题只是举例你看--}
for i :=0 to Fields.Count-1 do
StringGrid1.Cells[i,0]:='a'+inttostr(i);

while not eof do begin
StringGrid1.RowCount:=StringGrid1.RowCount+1;
for i :=0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[i,StringGrid1.RowCount-1]:=Fields[I].AsString;
next;
end;
end else begin

{导入的操作}

end;
next;
end;

end;
end;
end;
end;

这个GDTOPONE 您没有时间也没有关系,您进来DING一下就行,幸苦补分;

...全文
100 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GDTOPONE 2008-05-03
  • 打赏
  • 举报
回复

procedure TForm1.Button4Click(Sender: TObject);
var
s:string;
begin
if trim(edit1.Text) <>'' then begin
if adoquery1.FieldList.IndexOf(edit1.Text)>=0 then begin {-如果ADOQUERY1中有edit1中输入的字段-}
{---提取adoquery1的SQL语-----}
s := UpperCase(adoquery1.sql.Text);
if Pos('WHERE',s)>0 then
s := Copy(s,1,Pos('WHERE',s)-1) else
if Pos('ORDER',s)>0 then
begin
s := Copy(s,1,Pos('ORDER',s)-1);
end;

StringGrid1.ColCount:=0;{这里默认为五列}
StringGrid1.RowCount:=0;{这里默认为五行}

with adoquery2 do begin
First;{---------------------加了这句}
while not eof do begin
adolook.Close;
adolook.SQL.Text:=s+' where '+trim(edit1.Text)+'='+QuotedStr(adoquery2.FieldValues[trim(edit1.Text)]);
adolook.open;
if not adolook.IsEmpty then begin

{重复时写StringGrid用作显示}
StringGrid1.ColCount:=Fields.Count;
{--标题只是举例你看--}
for i :=0 to Fields.Count-1 do
StringGrid1.Cells[i,0]:='a'+inttostr(i);

while not eof do begin
StringGrid1.RowCount:=StringGrid1.RowCount+1;
for i :=0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[i,StringGrid1.RowCount-1]:=Fields[I].AsString;
next;
end;
end else begin

{导入的操作}

end;
next;
end;

end;
end;
end;
end;

崔玮 2008-05-03
  • 打赏
  • 举报
回复
指向最后一条了,再点还动么?
GDTOPONE 2008-05-03
  • 打赏
  • 举报
回复
示例文件夹里面有个名为test.xls的文件,我在这里测试过了,没有问题,你看是否对你有所帮助.
说明:
1.
数据库有两个表
x_eng
字段有 x_a,x_l

x_bng
字段有 xmm,xll


2.
同时导入test.xls的数据,当选择导入到表1时对比X_A这个字段,当选择导入表2时对比XMM这个字段,并将得复的记录显示在StringGrid中.

3.已将代码改为一个方法.
GDTOPONE 2008-05-03
  • 打赏
  • 举报
回复
留个邮箱地址,传示例比你,因为时间问题,所以写得比较急.

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧