Link to home
Start Free TrialLog in
Avatar of senad
senadFlag for Slovenia

asked on

delete from multiple tables with one button

I have 10 tables (ADOTable)
I display them in grid by means of radiobuttons i.e like this :

procedure TForm11.BitBtn1Click(Sender: TObject);
 Var I:integer;
begin
Case Radiogroup1.ItemIndex of
0: begin
for i:= 0 to Form11.ComponentCount - 1 do
if (Form11.Components[i] is TADOTable) then
(Form11.Components[i] as TAdoTable).Close;
ADOTable1.Open;
Datasource1.DataSet:=Adotable1 ;
end;

and so on for the remaining 9 tables.

Now,I added a query (ADOQuery1) so I can do some cleanup
with it.The basic cleanup parameters that I use to clean up tables
are the Autoinc field (ID) and the date field.
Example :

Adoquery1.Close;
Adoquery1.SQL.Clear;
AdoQuery1.SQL.Text:='delete from USERSLOG where USERSLOG.DATE between :d1 and :d2';
adoquery1.Parameters.ParamByName('d1').Value:= DateToStr(DateTimePicker1.Date);
adoquery1.Parameters.ParamByName('d2').Value:= DateToStr(DateTimePicker2.Date);
Adoquery1.ExecSQL;
AdoTable3.Requery();
or
Adoquery1.Close;
Adoquery1.SQL.Clear;
AdoQuery1.SQL.Text:='delete from log where log.id between :d1 and :d2';
adoquery1.Parameters.ParamByName('d1').Value:= Edit1.Text;
adoquery1.Parameters.ParamByName('d2').Value:= Edit2.Text;
Adoquery1.ExecSQL;
AdoTable1.Requery();

The problem is I would like to do cleanup with just one button.
So I guess I must tell the button on which table exactly to run the cleanup queery.
How do I do that???
I guess it could be done with stored procedures but I never used them before .
Baahh...Tell me your opinion and a solution.

Avatar of senad
senad
Flag of Slovenia image

ASKER

Or do I declare a global variable:
Var CurrentQuery:TADOQuery

then drop multiple queeries (for every radiobutton) and on button click

if TRadioButton(radioGroup1.Components[1]).Checked = True
 then
Currentquery:=ADOQuery1
    begin

  something like this.... ???
SOLUTION
Avatar of pcsentinel
pcsentinel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of senad

ASKER

I had it working another way but this way is simpler ...Thank's Geo...
Avatar of geobul
geobul

My pleasure :-)