一次删除多条记录


procedure TForm1.Button1Click(Sender: TObject);
var
  tempBookMark: TBookMark;
begin
  if DBGrid1.SelectedRows.Count >1 then s:= '真的要删除这些记录吗?';
  if Application.MessageBox (Pchar(s),'删除多条记录',mb_iconinformation+mb_yesNo)=idYes then
  begin
    DBGrid1.DataSource.DataSet.DisableControls ;
    i:=0;
    While i<= DBGrid1.SelectedRows.Count -1 do
    begin
      DBGrid1.DataSource.DataSet.Bookmark:= DBGrid1.SelectedRows.Items[i];  //重要在这里取得bookmark
     
      TempBookmark := DBGrid1.Datasource.Dataset.GetBookmark;

      DBGrid1.DataSource.DataSet.GotoBookmark(TempBookMark);
      DBGrid1.DataSource.DataSet.Delete ;
      DBGrid1.DataSource.DataSet.FreeBookmark (TempBookMark);
      Inc(i);
    end;
    DBGrid1.DataSource.DataSet.EnableControls;
  end;

end;

你可能感兴趣的:(删除)