0

I have 4 ClientDataSets like this:

Master

---Detail 1

---Detail 2

------SubDetail 2.1 - here there is a FK to Detail 1

The insert order of records on datasets is: Master, Detail 1, Detail 2, SubDetail 2.1.

However, the insert order on database, when I call ApplyUpdates, is Master, Detail 2, SubDetail 2.1, Detail 1.

So I get an error "Foreign key reference target does not exist", because there is a FK on SubDetail 2.1, that point to a record on Detail 1, which isn't inserted on database yet.

Can I change the post order of nested datasets on database? Or is there another way to fix this problem?

dsonda
  • 61
  • 3

1 Answers1

0

You can use the following on your datasets

procedure TTemplate.MasterpostBeforeInsert(DataSet: TDataSet);
begin
  if Assigned(Dataset.DataSource) and Assigned(Dataset.DataSource.DataSet) then
    if Dataset.DataSource.DataSet.State in [dsInsert] then 
      Dataset.DataSource.DataSet.Post;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
bummi
  • 27,123
  • 14
  • 62
  • 101