problem with master-detail
problem with master-detail
I am using BDS 2006 and sdac 450 pro.
I have 2 table reservation and reservationdetail.
reservation:
- ReservationID (autoinc)
reservationdetail :
- ReservationDetailID (autoinc)
- reservationID (fk to reservation)
master tmsquery setting :
SQL = Select * from reservation
cachedupdate = true
returnparams = true
detail tmsquery setting :
SQL = select * from reservationdetail where reservationid=:reservationid
mastersource = master
cahcedupdate = true
returnparams = true
localmasterdetail = true
However the master-detail won't work. i have dbgird to show my detail data but it still empty.
I've try to use masterfield and detailfield solution like you did in the doc. It's work HOWEVER i can't append a new data on detail dbgrid beacuse the data will disappear every time i post or append new record.
Am i doing something wrong? Thanks before.
I have 2 table reservation and reservationdetail.
reservation:
- ReservationID (autoinc)
reservationdetail :
- ReservationDetailID (autoinc)
- reservationID (fk to reservation)
master tmsquery setting :
SQL = Select * from reservation
cachedupdate = true
returnparams = true
detail tmsquery setting :
SQL = select * from reservationdetail where reservationid=:reservationid
mastersource = master
cahcedupdate = true
returnparams = true
localmasterdetail = true
However the master-detail won't work. i have dbgird to show my detail data but it still empty.
I've try to use masterfield and detailfield solution like you did in the doc. It's work HOWEVER i can't append a new data on detail dbgrid beacuse the data will disappear every time i post or append new record.
Am i doing something wrong? Thanks before.
thank you for quick response....
However i've done what you said.
I've also add this:
My real problem is, after i apply updates my change and i re-run my application, the master-detail won't work. i get master data but detail dbgid is empty (I am using master-detail with parameter)

However i've done what you said.
Code: Select all
if dmReservation.QReservation.State in [dsedit, dsinsert] then begin
dmReservation.QReservation.Connection.StartTransaction;
try
dmReservation.QReservation.ApplyUpdates;
dmReservation.QReservationDetail.ApplyUpdates;
dmReservation.QReservation.Connection.Commit;
dmReservation.QReservation.CommitUpdates;
dmReservation.QReservationDetail.CommitUpdates;
BrowseMode;
except
dmReservation.QReservation.RestoreUpdates;
dmReservation.QReservationDetail.RestoreUpdates;
dmReservation.QReservation.Connection.Rollback;
end;
end;
Code: Select all
// for master table
procedure TdmReservation.QReservationBeforeUpdateExecute(
Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
begin
if stInsert in StatementTypes then begin
Params.ParamByName('ReservationID').ParamType:=ptInputOutput;
end;
end;
//for detail table
procedure TdmReservation.QReservationDetailBeforeUpdateExecute(
Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
begin
if stInsert in StatementTypes then begin
Params.ParamByName('ReservationID').AsInteger:=QReservationReservationID.AsInteger;
end;
end;