Hello everyone, I am using Delphi2010 and I'm trying to do an insert into multiple tables. I don't know the best way to do this. What I'm wondering is if there is a possible way to do one insert using one of Delphi's tools like the TQuery or TClientDataSet or would it be better to use code (we use Pascal language). An array maybe? I haven't been using Delphi that long but I have inserted and updated info into one table before, not multiple. Also, these tables use pretty much the same field names.

Any help would be greatly appreciated.

Thanks in advance!!

Personally I prefer to reuse a TQuery. You could create an array of strings containing all you queries and execute them in a loop using one TQuery.

Thanks for responding!

Well, I tried using a TQuery to actually experiment with a basic sql:

insert into conf_tax_rep_info
(casenum, name, company, addr_1, addr_2, city, state, zip)
values (:CASENUM, :NAME, :CO, :ADD1, :ADD2, :CITY, :STATE, :ZIP)

but I received a "invalid variable name/number" sql so I tried to use this code to experiment with a basic sql(I am using Oracle to insert my rows):

dm.OracleQuery1 := TOracleQuery.Create(Nil);
dm.OracleQuery1.Session := dm.OS;
dm.OracleQuery1.Close;
dm.OracleQuery1.SQL.Clear;
casenum := 1;
DM.OracleQuery1.DeclareAndSet(':CaseNum', otinteger, casenum);
dm.OracleQuery1.Declareandset(':Name', otstring, Trim(edTaxRepName.text));
dm.OracleQuery1.declareandset(':CO', otstring, Trim(edTaxRepComp.text));
dm.OracleQuery1.declareandset(':ADD1', otstring, Trim(edTaxRepaddr1.text));
dm.OracleQuery1.declareandset(':ADD2', otstring, Trim(edTaxRepaddr2.text));
dm.OracleQuery1.declareandset(':CITY', otstring, Trim(edTaxRepCity.text));
dm.OracleQuery1.declareandset(':STATE',otstring, Trim(edTaxRepState.text));
dm.OracleQuery1.declareandset(':ZIP', otstring, Trim(edTaxRepZip.text));
ssql :=
'insert into conf_tax_rep_info(casenum, name, company, addr_1, addr_2, ' +
'city, state, zip) values (:CaseNum, :NAME, :CO, :add1, :add2, :city, ' +
':state, :zip)';

dm.OracleQuery1.SQL.Text := sSQL;
dm.OracleQuery1.Execute;
dm.OracleQuery1.Close;

which works but I need to add 3 more tables to the sql statement which include some of the same field names and thought there has to be a better way to do this because there would be way too much unnecessary coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.