We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GBDG Master-Detail and Identity Column problem

Thread ID:

Created:

Updated:

Platform:

Replies:

28769 May 10,2005 11:10 AM May 15,2005 01:46 PM Windows Forms 8
loading
Tags: GridControl
Helmut Scheiss
Asked On May 10, 2005 11:10 AM

Here''s one for the crowd regarding Master-Detail Databound Grids and Identity columns. I have 2 grids, one master and one detail. I''ll make a 3 column example for brevity: Table: Master RecID : int : Identity GroupID: int Description: char(50) Table: Detail DetRecID: int: Identity GroupID: int DetailDescription: char(100) As you can see, the two tables have a relationship on GroupID. My situation is the identity column in the Detail table not producing unique columns until the underlying dataset is updated. For example, when first loading the form and with the first record selected, RecID=0, the 2 grids would like this: Master Table: RecID GroupID Desc 0 1 Adams 1 2 Baker 2 3 Charlie Detail Table: DetRecID GroupID Desc 100 1 Adams Detail 101 1 More Adams Detail 102 1 Even More Detail Selecting the next master record, which doesn''t have any detail records looks like this: Master Table: RecID GroupID Desc 1 2 Baker Detail Table: DetRecID GroupID Desc 0 2 *Adding another detail record does this: 1 2 When I try to update the dataset, any of the "new" detail entries will be lost. However, if we repeat the same process, the Detail grid looks like this DetRecID GroupID Desc 103 2 It correctly seeds the identity column in the Details table. What am I doing wrong or not seeing? Thank you!

Administrator [Syncfusion]
Replied On May 10, 2005 11:29 AM

Something to try: When the details grid gets focus, try calling CurrencyManager.Refresh for its currencymanager. So maybe in the detailsGrid.Enter event, have code like: CurrencyManager cm = detailsGrid.BindingCOntext[detailsGrid.DataSOurce, detailsGrid.DataMember] as CurrencyManager; cm.Refresh();

Helmut Scheiss
Replied On May 10, 2005 12:23 PM

Thanks for the quick response, but still no dice. The DetRecID still defaults to 0. Any other ideas? >Something to try: When the details grid gets focus, try calling CurrencyManager.Refresh for its currencymanager. > >So maybe in the detailsGrid.Enter event, have code like: > >CurrencyManager cm = detailsGrid.BindingCOntext[detailsGrid.DataSOurce, detailsGrid.DataMember] as CurrencyManager; >cm.Refresh(); >

Administrator [Syncfusion]
Replied On May 10, 2005 02:13 PM

If you can upload a sample project showing the problem, we can try to debug into it.

Helmut Scheiss
Replied On May 12, 2005 03:15 PM

I think I''ve found out what is causing the problem. Here''s an example: I load my form with 2 datagrids, Master and Detail. Let''s say there is one record in the Master and 0 in the Detail: Master DetailID (identity fld) = 1 Description = "Master 1" When I enter a new Master record, it is assigned a DetailID of 2. I now enter new records in Detail. They are related on DetailID so the Detail grid looks like this: DetailID=2 DetailDesc="Detail line 1" DetailID=2 DetailDesc="Detail line 2" DetailID=2 DetailDesc="Detail line 3" When I update the dataset, there are already records in the Master table with a DetailID=2. The Master record saves and comes back DetailID=100. This blows away the relationship with the previously entered Detail records and they do not save. Is it possible to force the value of the Master table DetailID to the next identity value by setting it upon the first time the Master grid loads or commit each new Master record (thus getting a valid Master DetailID)? Or begin the commit and refresh the data in both grids when the current row loses focus, ie., clicks on another row, another grid, etc? I''m in a real jam with this one. Thank you.

Helmut Scheiss
Replied On May 12, 2005 03:36 PM

Oh let me add that if I add multiple master records before saving, the first one and all of its detail records will save, but the detail records of all the others do not save and "disappear".

Helmut Scheiss
Replied On May 13, 2005 12:07 AM

After analyzing this bug, I''ve concluded: 1. When the master data table is updated it returns new identity values to the Master dataset (ID1). 2. Any Detail record entered under a new (added) Master record, will not be saved. 3. There is a constraint built into the relationship between the two tables on ID1 (The primary key in Master and Foreign key in Detail.) Is there a certain way I have to configure my Dataset or DataAdapter parms? As always, thank you. HS

Administrator [Syncfusion]
Replied On May 13, 2005 09:01 AM

Here is a link to a master details sample with primary keys set in both tables. http://www.syncfusion.com/Support/user/uploads/MasterDetails_5bfaf1c8.zip How can I see the problem you are having in this sample?

Helmut Scheiss
Replied On May 15, 2005 01:46 PM

Thanks for the help. Unfortunately, the example provided is too basic. I''m already doing everything in the example, such as setting the datasource of the detail table to the name of the relationship. The problem I''m having is adding new records to the master grid. The PK (which is the FK in the detail table) is not generating correctly. What''s really wierd is that I wrote some code to update the master grid when the current Master Row lost focus and it does update the PK and FK in the detail. However, the detail info is lost during the update. Thank again. >Here is a link to a master details sample with primary keys set in both tables. > >http://www.syncfusion.com/Support/user/uploads/MasterDetails_5bfaf1c8.zip > >How can I see the problem you are having in this sample?

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;