problem with master-detail

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
yulianto
Posts: 5
Joined: Thu 11 Sep 2008 02:58

problem with master-detail

Post by yulianto » Thu 11 Sep 2008 03:12

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.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 11 Sep 2008 08:34

When you use the CachedUpdates mode you should write dataset's changes to a database using the TMSQuery.ApplyUpdates and the TMSQuery.CommitUpdates methods.

yulianto
Posts: 5
Joined: Thu 11 Sep 2008 02:58

Post by yulianto » Thu 11 Sep 2008 08:42

thank you for quick response.... :)

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;
I've also add this:

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 11 Sep 2008 08:55

Please try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

yulianto
Posts: 5
Joined: Thu 11 Sep 2008 02:58

Post by yulianto » Thu 11 Sep 2008 09:38

i've sent you the sample...

thanks in advance. :lol:

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 11 Sep 2008 14:36

Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next SDAC build.

yulianto
Posts: 5
Joined: Thu 11 Sep 2008 02:58

Post by yulianto » Fri 12 Sep 2008 07:56

do you have any alternative solution for this problem? at least until the next build released...

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 15 Sep 2008 08:02

Unfortunately, we don't have an alternative solution for this problem. If you can, don't use the CahcedUpdate mode.

lifeform
Posts: 22
Joined: Wed 02 Jan 2008 05:34

Post by lifeform » Thu 18 Sep 2008 06:18

when the next release released???
please tell us the estimated date so we can estimate our project too

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 19 Sep 2008 08:00

The next SDAC build will be released at the beginning of the next week.

Post Reply