Master Detail Single button for commit lazarus / 16-Databases ---------------------------------------------------------------------- anis2505 · 2015-11-26 18:15 Hi all, Simply I need to know how is it possible to commit all changes with single button click. I have two SQLQuery components. and a 1 SQLTransaction. So I want to click a button and all data will be commited to database. Sorry to bother. I don't have so many time to dig the forum. regads GH.Anis ---------------------------------------------------------------------- LacaK · 2015-11-26 19:11 SQLTransaction.Commit or SQLTransaction.CommitRetaining ---------------------------------------------------------------------- anis2505 · 2015-11-26 20:53 Quote from: LacaK on November 26, 2015, 08:11:58 pmSQLTransaction.Commit or SQLTransaction.CommitRetaining Hi thanks My problem how to commit all SQLQuery component's updates. Code: [Select] //Master SQLQuery component SQLMaster.ApplyUpdates; // Detail SQLQuery component SQLDetail.ApplyUpdates; //Commit Updates SQLTrasaction.Commit; The problem only the master's updates gets commited, the detail's updates gets are ignored ---------------------------------------------------------------------- LacaK · 2015-11-27 06:34 It should work. Do you have on database side defined any referential integrity constraints ? When you in same transaction close and open datasets data are there ? (if not it means that they are not written to database...so it is primary not problem of commiting transaction, but applying updates) ---------------------------------------------------------------------- fpcoder · 2015-11-27 08:46 Are you posting the detail changes before calling ApplyUpdates? ---------------------------------------------------------------------- anis2505 · 2015-11-27 11:18 Quote from: kapibara on November 27, 2015, 09:46:28 amAre you posting the detail changes before calling ApplyUpdates? I don't understand what do you mean exactly. do you mean calling the Post method from th SQLDetail component. I'm using DBNav to handle the posting ---------------------------------------------------------------------- rvk · 2015-11-27 12:07 How are SQLMaster and SQLDetail connected? If you insert a new record in SQLMaster you need to get a unique ID for that record. You need to use that unique ID and put it in the foreign key of SQLDetail. Otherwise, if you don't assign the foreign key in SQLDetail, it gets saved as NULL and you can only reach the detail records if you do a complete SELECT (but the connection with the SQLMaster is lost). If you do a SELECT * on your SQLDetail (in a SQL manager without the master table) do you see your posted records from before? ---------------------------------------------------------------------- anis2505 · 2015-11-27 12:34 Hi  , Here is a working example.   What I need to achieve is to use one button to post all data from the master and the detail regards GH.Anis ---------------------------------------------------------------------- rvk · 2015-11-27 12:56 Quote from: anis2505 on November 27, 2015, 01:34:30 pm What I need to achieve is to use one button to post all data from the master and the detail The problem is that you can only post detail records if the master is already posted. You now have a CUSTOMER_ID. Do you assign that manually in your master-table? You now have this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TDataCenter.SQLArticleAfterInsert(DataSet: TDataSet);begin  DataSet.FieldByName('CUSTOMER_ID').Value := SQLCustomer.FieldByName('CUSTOMER_ID').Value;end;I see now that you haven't even connected the SQLArticleAfterInsert to any SQLArticle dataset. So it doesn't even work. You don't have ANY of those event connected. If you connect the events you can create a new button with applyupdates and commit and it should work. When entering a new customer a post needs to be done before inserting a new article (otherwise the detailrecord can't see the new master). In the DBGrid this is done automatically if you select another row or with the green check-sign. ---------------------------------------------------------------------- chtilux · 2022-09-20 07:27 Hi, I've got the same problem. Database : Firebird 4.0 Components : TSQLConnector, TSQLTransaction, TSQLQuery. Master Query and DetailQuery are linked by Datasource. Displaying records id ok. But when I insert more detail records for the same master record, only one is there when I reopen the form. The same if I insert a new master record then a new detail (first master.post of course), the master is inserted into the database but the detail not. Thanks. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TProductW.SalesQueryNewRecord(DataSet: TDataSet);begin  Dataset.FieldB yName('serprd').Value:=Query.FieldByName('serprd').AsInteger;  Dataset.FieldByName('dateff').Value:= Validity.Date;  Dataset.FieldByName('ptype').Value:='S';  Dataset.FieldByName('qtymin').Value:=1;end; procedure TProductW.saveContent;begin  try    if DataObject.Transaction.Active then    begin      Query.ApplyUpdates;      SalesQuery.ApplyUpdates;    DataObject.Transaction.Commit;    end;  except    on E:EDatabaseError do    begin      DataObject.Transaction.Rollback;    MessageDlg(E.Message, mtError, [mbOk], 0);    end;  end;end;  [code=pascal] ---------------------------------------------------------------------- rvk · 2022-09-20 07:42 Quote from: chtilux on September 20, 2022, 09:27:11 amBut when I insert more detail records for the same master record, only one is there when I reopen the form. You need to show more of the relevant code. If you only call TProductW.saveContent once, then yes, you'll only get one record. You need to post and applyupdates for every subrecord you want to save. ---------------------------------------------------------------------- chtilux · 2022-09-20 08:32 @rvk Thank you for the answer, it helps me ;-) I thought ApplyUpdates would apply all updatesPrending of the dataset to the database. QuoteIf you only call TProductW.saveContent once, then yes, you'll only get one record. You need to post and applyupdates for every subrecord you want to save. ---------------------------------------------------------------------- Zvoni · 2022-09-20 10:21 …… and people laugh at me, when i say i don‘t bother with that, but do everything via SQL-Statements……