Problem Working With TableAdapterManager with 3 Tables RRS feed

  • Question

  • Hi,

    I'm using a 3 table hierarchy such that Table1 is parent of Table2 and Table2 is parent of Table3. For a single record of Table1, there are multiple records of Table2 and similarly for each record of Table2, there are multiple records of Table3. I'm using TableAdapterManager to accomplish my task, which is to commit all the changes made in these 3 tables, with the single call of UpdateAll() method of TableAdapterManager.

    The problem i'm facing is that the data is committed in the first two tables, but not in the third one. Unfortunately, i've not found any sample with the same scenario. I've used TableAdapters of first two tables in TableAdapterManager. The third table is on different form with the same DataSet, and the data is populating by Table2's primary key value, when we double click the Table2's record. In this form, TableAdapter2's Fill method is used to populate the data. Each time i navigate into this form, this table adapter has modified to have only those values which are related to the Table2's primary key.

    And, when i save the changes, it commits the data of first table and all records of 2nd table, but only the last record of 3rd table. Instead, it should save all records of table3. What is the problem, is i already mentioned in above paragraph that Table3 TableAdapter is updating each time. Any help in this regard will be hightly appreciated.!!



    Friday, January 11, 2013 12:50 PM

All replies

  • Ovais,

    Nice description, but can you also show how your Update code part works?

    We are not looking through your eyes you know.


    Saturday, January 12, 2013 2:11 PM
  • It probably has something to do with uncommitted changes in the child rows of Table3. See my blog post about this, it may help:

    ~~Bonnie Berent DeWitt [C# MVP]

    Saturday, January 12, 2013 10:56 PM
  • Cor,

    Let me try to elaborate in simple. Look, my parent table binding source consist of some textbox fields on Form1. Each time I instantiate Form1, i call bindingsource.AddNew() method for the parent table.

    Then i've a datagrid on same form i.e. Form1, which is bind to childTable binding source. I'm populating datagrid by using parent's primary key. i.e. adapter2.FillByPKey(ds.ChildTable1, ParentKey). Its going fine upto this point.

    Now I've an another form Form2 which consist of another datagrid and is a childTable of DataGrid's record (which is at Form1). It means that when I click on Form1's grid's record, it navigates me to the Form2, and the grid on that form is populating as adapter3.FillByKey(ds.ChildTable2, ChildKey). This ChildKey is the primary key of data grid's record on Form1. Hope you are now clear with the explained scenario. There is a Save button on Form1, which when called, i've used:

    adapterManager.TableAdapter1 = me.DataSet.TableAdapter1

    adapterManager.TAbleAdapter2 = me.DataSet.TableAdapter2


    One more thing to note. I'm setting adapterManager.TableAdapter3 = me.DataSet.TableAdapter3 each time when i close Form2 and back to Form1.

    My UpdateAll() command only commit Table1 and Table2 records (all records in grid) and only the last record of Table3 (only the last record in the grid on 2nd form.)

    I hope now you will be able to answer my question..


    Monday, January 14, 2013 6:06 AM
  • Have you at least tried my suggestion?

    ~~Bonnie Berent DeWitt [C# MVP]

    Monday, January 14, 2013 9:54 PM