with Query do begin first; while not Query.Eof do begin Query.delete; Query.Next; end; end;
To: arg(雨隼) 你那样是一个死循环。
procedure TForm1.Button2Click(Sender: TObject); begin AdoQuery1.UpdateBatch(arall); end;procedure TForm1.Button3Click(Sender: TObject); begin AdoQuery1.CancelBatch(arALL); edit1.Text:=IntToStr(AdoQuery1.Recordcount); end;procedure TForm1.Button1Click(Sender: TObject); begin AdoQuery1.Open; AdoQuery1.First; while not AdoQuery1.Eof do begin AdoQuery1.Delete; // AdoQuery1.Next; end; edit1.Text:=intToStr(AdoQuery1.RecordCount); end;procedure TForm1.FormShow(Sender: TObject); begin edit1.Text:=IntToStr(AdoQuery1.RecordCount ); end; 特此声明:arg(雨隼)是对的。刚才我上机测试成功。不好意思。以后一定要严禁。
Query.Delete
Query.Next;
end;
不过不要少写了个 do
to zyj320621(小朱)
错了,按你的写法query中会删除一条,不删一条。应为query中delete方法会将当前移动到下一条。正确的写法应该是Query.first;
while not Query.eof do
query.delete;
begin
first;
while not Query.Eof do
begin
Query.delete;
Query.Next;
end;
end;
Query1.CommitUpdata;//更新到数据库
while not Query.Eof do
begin
Query.delete;
Query.Next;
end;
最好的方法还是用Delete语句来删除符合条件的。以上代码都要在Requestlive为True的情况下执行,但是Query是不支持对复杂SQL语句的查询结果进行编辑操作的。
begin
first;
while not Query.Eof do
begin
Query.delete;
Query.Next;
end;
end;
begin
AdoQuery1.UpdateBatch(arall);
end;procedure TForm1.Button3Click(Sender: TObject);
begin
AdoQuery1.CancelBatch(arALL);
edit1.Text:=IntToStr(AdoQuery1.Recordcount);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
AdoQuery1.Open;
AdoQuery1.First;
while not AdoQuery1.Eof do
begin
AdoQuery1.Delete;
// AdoQuery1.Next;
end;
edit1.Text:=intToStr(AdoQuery1.RecordCount);
end;procedure TForm1.FormShow(Sender: TObject);
begin
edit1.Text:=IntToStr(AdoQuery1.RecordCount );
end;
特此声明:arg(雨隼)是对的。刚才我上机测试成功。不好意思。以后一定要严禁。