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. Image for the cookie policy date
close icon

GBDG Master-Detail and Identity Column problem

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!

8 Replies

AD Administrator Syncfusion Team May 10, 2005 03:29 PM UTC

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


HS Helmut Scheiss May 10, 2005 04:23 PM UTC

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


AD Administrator Syncfusion Team May 10, 2005 06:13 PM UTC

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


HS Helmut Scheiss May 12, 2005 07:15 PM UTC

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.


HS Helmut Scheiss May 12, 2005 07:36 PM UTC

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".


HS Helmut Scheiss May 13, 2005 04:07 AM UTC

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


AD Administrator Syncfusion Team May 13, 2005 01:01 PM UTC

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?


HS Helmut Scheiss May 15, 2005 05:46 PM UTC

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?

Loader.
Live Chat Icon For mobile
Up arrow icon