C# DataAdapter and DataSet with multiple table
Asked Answered
F

1

6

I have read from many places that it is possible to fill a DataSet with multiple tables using a DataAdapter. It also does not say whether a single Update call can update all the tables in the DataSet.

Can someone help me figure out how this can be done?

It seems like there isn't any ( i tried finding online ) examples on how to do it except for one that changes the SelectCommand on the DataAdapter before the second fill. But I feel this method defeats the purpose of the DataAdapter.

From what I figure, perhaps a single DataAdapter can only handle a single database table and Update only works on that table. Hence a multi-table DataSet will require respective DataAdapters call their Update to fully update the DataSet. Is this the case?

Finally, will foreign key relations and contraints hold in a DataSet (cascade delete, cascade update) automatically?

Maybe a link to an example or tutorial might help. Many thanks!

Farthermost answered 1/1, 2011 at 16:3 Comment(0)
T
5
  1. Yes it is true that, Single Adapter for single table.But

  2. You can use Use table adapter manager for saving all at once, table adapter manager can have many individual adapters and you can call save for all. like, So no need to call save multiple time also it has other features too.

    public void SaveWithManager()
    {
    DataSet1TableAdapters.TableAdapterManager mgr1 = new DataSet1TableAdapters.TableAdapterManager();
    DataSet1TableAdapters.Table1TableAdapter taTbl1 = new DataSet1TableAdapters.Table1TableAdapter();
    DataSet1TableAdapters.Table2TableAdapter taTbl2 = new DataSet1TableAdapters.Table2TableAdapter();
    
    
    mgr1.Table1TableAdapter = taTbl1;
    mgr1.Table2TableAdapter = taTbl2;
    mgr1.UpdateOrder = DataSet1TableAdapters.TableAdapterManager.UpdateOrderOption.InsertUpdateDelete; 
    mgr1.UpdateAll(your dataset);
    

    }

  3. Finally cascade update delete is handled in dataset. You can view properties of relation and various options for cascade.(Typed dataset)

Twirl answered 1/1, 2011 at 18:13 Comment(1)
+1 for letting me know something new about the designer. thanks.Farthermost

© 2022 - 2024 — McMap. All rights reserved.