Topic: Clear all content of table

Hello,
Could someone explain to me how to make a button that will erase the entire contents of a table and leave the counter to zero?
Thanks,

Re: Clear all content of table

Hello,



You can do it using script, example:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.TableGrid1.ClearRows;
end;
Dmitry.

Re: Clear all content of table

DriveSoft wrote:

Hello,



You can do it using script, example:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.TableGrid1.ClearRows;
end;

Thanks Dimitri!
But this only clear the grid. I want erase all records from a table of a database, inluded field named "ID". Could you help me please?

Re: Clear all content of table

Hello meideprac-x


You can use this script behind a button :

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
     SQLExecute('DELETE FROM Employees');
end;

Be careful : You can't come back with deleted data,
but the structure of your table is always available

JB

5 (edited by meideprac-x 2016-06-01 20:50:12)

Re: Clear all content of table

Thanks JB!!! Thats works fine, but now, how can I reset to 0 field IDENTITIE for this cleared table??

Re: Clear all content of table

Using Jean's example you can do the following to reset the ID field in the EMPLOYEES table:
SqlExecute('Delete from sqlite_sequence where name=''Employees''');

Re: Clear all content of table

ehwagner wrote:

Using Jean's example you can do the following to reset the ID field in the EMPLOYEES table:
SqlExecute('Delete from sqlite_sequence where name=''Employees''');

Thanks ehwagner!! Works OK