 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Slavisa Cicovic Guest
|
Posted: Fri Jan 30, 2004 2:40 am Post subject: dbExpress: MAster Detail |
|
|
I make SQLTables in m-d relationship, link master ClientDataSet to
DataSetProvider, and details to master's DataSetFields.
( For genereting AutoInc fields I'm using schema from Eric Harmon book
'Delphi/Kilyx database development'):
1.(All 3 cds have field ID)
procedure TDataModule2.ClientDataSet1NewRecord(DataSet: TDataSet);
begin
DataSet.FieldByName('ID').AsInteger :=
GetNextID(DataSet as TCustomClientDataSet, 'ID');
end;
2. sqlGuestsTable is a master and has field ID which is pk,
sqlGuestsIDsTable has field GUEST_ID which is fk,
sqlGuestsResTable has field GUEST_ID which is fk, to
FGuestID: integer is private field in DataModule2. For new record on
master cds FGuestID holds master ID, and it works fine for new master's
records, but not for details. Whats wrong?
procedure TDataModule2.pvGuestsBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind; var Applied: Boolean);
begin
if UpdateKind = ukInsert then
begin
if DeltaDS.FieldByName('ID').OldValue <= 0 then
DeltaDS.FieldByName('ID').NewValue := ServerGetNextID;
if SourceDS = sqlGuestsTable then
FGuestID := DeltaDS.FieldByName('ID').NewValue;
if SourceDS = sqlGuestIDsTable then
begin
DeltaDS.FieldByName('GUEST_ID').NewValue := FGuestID;
end;
if SourceDS = sqlGuestResTable then
DeltaDS.FieldByName('GUEST_ID').NewValue := FGuestID;
end;
end;
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|