Search code examples
delphidelphi-xe5firedac

Delphi Delete all records from FDTable


Iam trying to delete all records in my FDTable component using ,

mytable.Delete;

but no record is getting deleted.

can any one suggest me a way to delete all records in a FdTable.

EDIT

i modified it in this way,

  for i := mytable.RecordCount - 1 downto 0 do
  begin
    mytable.Delete;
  end;
  mytable.Refresh;

but it is taking lot of time because there a lot rows in my fdtable.


Solution

  • Remove all the records in the underlying database table (the best way to do that will depend on the database) and call refresh just once.

    If you must do it via TFdTable, use BeginBatch, do your deletes (without refresh), EndBatch and only then Refresh.

     mytable.BeginBatch;
     for i := mytable.RecordCount - 1 downto 0 do
     begin
        mytable.Delete;
     end;
     mytable.EndBatch;
     mytable.Refresh;