Forum > Databases

Master Detail Single button for commit

<< < (2/3) > >>

anis2505:

--- Quote from: kapibara on November 27, 2015, 09:46:28 am ---Are you posting the detail changes before calling ApplyUpdates?

--- End quote ---

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:
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:
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:

--- 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

--- End quote ---
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TProductW.SalesQueryNewRecord(DataSet: TDataSet);begin  Dataset.FieldByName('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]

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version