Master/Detail Relatioship Broke

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jigesh
Posts: 16
Joined: Tue 11 Oct 2005 21:04

Master/Detail Relatioship Broke

Post by jigesh » Mon 11 Oct 2010 16:59

Hi

After upgrading from SDAC 3.70.2.28 to SDAC 5.00.0.1 my Master/Detail relationship is broken. I cannot see any detail records. If I run my app which was complied with the old version everything works fine. Are there any new settings I should be aware when using the latest version od SDAC? All my relations are setup correctly. I have the master dataset as the MasterSourceDataset for the detail dataset. Please help. I have many master/detail relationsships in my app.

Thanks

From
Jigesh

AndreyZ

Post by AndreyZ » Tue 12 Oct 2010 07:49

Hello,

I couldn't reproduce the problem. I have created a master/detail relationship using SDAC 3.70.2.28 and it correctly works with SDAC 5.00.0.1. Please, try creating a new master/detail relationship using SDAC 5.00.0.1. If it doesn't work then check that you don't have any old dcu files from SDAC 3.70.2.28 in your project. If the problem persists, please post here the piece of code where you are initializing the master/detail relationship.

tyassin
Posts: 2
Joined: Sat 09 Feb 2008 12:20

Post by tyassin » Wed 13 Oct 2010 17:53

Jigesh is right. I just discovered that today. To reproduce it is simple:

1- Create a table: Cats (ID, Name) and fill it with some data.
2- Create another table: Products (ID, Name, CatID)
3- Add the two tables to a form and create the necessary master-detail relation ship
4- Add DBEdit components for the Products fields
5- Add DBLabel and link it to Cats.Name
6- Now, when you add a new product and write a CatID that exists in the Cats table, the DBLabel show the name correctly. This behavior is broken in 5.00.0.1.
7- If you save the record and open it again, it will show the category name correctly.
8- Now, the only way to get the correct behavior back is to add an OnExit even to the DBEdit of the Products.CatID where you have to Cats.Close and Cats.Open. Refresh doesn't work.

AndreyZ

Post by AndreyZ » Thu 14 Oct 2010 08:44

I'm using the following code to establish master/detail relationship between two tables:

Code: Select all

  tblMaster.TableName := 'Emp';
  tblDetail.TableName := 'Dept';
  tblDetail.MasterSource := dsMaster;
  tblDetail.MasterFields := 'ID';
  tblDetail.DetailFields := 'EmpID';

  DBText_EmpName.DataSource := dsMaster;
  DBText_EmpName.DataField := 'Name';
  DBEdit_DeptID.DataSource := dsDetail;
  DBEdit_DeptID.DataField := 'ID';
  DBEdit_DeptName.DataSource := dsDetail;
  DBEdit_DeptName.DataField := 'Name';
  DBEdit_DeptEmpID.DataSource := dsDetail;
  DBEdit_DeptEmpID.DataField := 'EmpID';

  tblMaster.Open;
  tblDetail.Open;
I'm using the following code to add a new record to the detail table (button click):

Code: Select all

  tblDetail.Append;
  tblDetail.FieldByName('ID').AsInteger := StrToInt(edNewDeptID.Text);
  tblDetail.FieldByName('Name').AsString := edNewDeptName.Text;
  tblDetail.FieldByName('EmpID').AsInteger := StrToInt(edNewDeptEmpID.Text);
  tblDetail.Post;
Are you using the same code? If no, please, correct it so I can reproduce the problem. If yes, specify which component behaves incorrectly?
Also you can compose a small sample to demonstrate the problem and send it to andreyz*devart*com.

tyassin
Posts: 2
Joined: Sat 09 Feb 2008 12:20

Post by tyassin » Thu 14 Oct 2010 13:24

Project and Tables sent by mail as requested.

All you have to do is Insert a new record and input 1 or 2 as the product type.

AndreyZ

Post by AndreyZ » Fri 15 Oct 2010 10:44

To solve the problem set the RefreshParamsOnInsert global variable from the DBAccess unit to True. Notice that if you have a lot of master/detail relationships, setting this variable to True may cause performance decreasing.

jigesh
Posts: 16
Joined: Tue 11 Oct 2005 21:04

Post by jigesh » Fri 15 Oct 2010 18:31

AndreyZ wrote:To solve the problem set the RefreshParamsOnInsert global variable from the DBAccess unit to True. Notice that if you have a lot of master/detail relationships, setting this variable to True may cause performance decreasing.
Where do I find RefreshParamsOnInsert option. Which dataset is involved.

Thanks

Jigesh

AndreyZ

Post by AndreyZ » Mon 18 Oct 2010 09:20

RefreshParamsOnInsert is a global variable from the DBAccess unit. To use it, add DBAccess unit in the uses clauses of your unit and write the following code:

Code: Select all

RefreshParamsOnInsert := True;
All datasets use this variable for master/detail relationships.

jigesh
Posts: 16
Joined: Tue 11 Oct 2005 21:04

Post by jigesh » Wed 20 Oct 2010 14:29

AndreyZ wrote:RefreshParamsOnInsert is a global variable from the DBAccess unit. To use it, add DBAccess unit in the uses clauses of your unit and write the following code:

Code: Select all

RefreshParamsOnInsert := True;
All datasets use this variable for master/detail relationships.
Hi AndreyZ,

Your suggestion worked very well for me.

Thanks

AndreyZ

Post by AndreyZ » Wed 20 Oct 2010 14:39

I am happy that this problem has been solved. If any other questions come up, please contact me.

Post Reply