在delphi中我用DBGrid选择多条记录,如何一次把选择的多条记录删掉
procedure TForm1.btnDoSumClick(Sender: TObject);
var
i: Integer;
begin
if DBGrid1.SelectedRows.Count > 0 then
begin
with DBGrid1.DataSource.DataSet do
begin
for i := 0 to DBGrid1.SelectedRows.Count-1 do
begin
GotoBookmark(Pointer(DBGrid1.SelectedRows.Items[i]));
self.ADOQuery1.Delete;//删除记录
end;
end;
end
end;
我的这段程序是这样的.
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('删除前记录数:'+IntToStr(ADOQuery1.RecordCount));
try
DBGrid1.SelectedRows.Delete;
except
end;
ADOQuery1.Close;
ADOQuery1.Open;
ShowMessage('删除后记录数:'+IntToStr(ADOQuery1.RecordCount));
end;
好的代码像粥一样,都是用时间熬出来的