C# DataAdapter and DataSet with multiple table

前端 未结 2 1147
盖世英雄少女心
盖世英雄少女心 2020-12-19 09:03

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

相关标签:
2条回答
  • 2020-12-19 09:35
    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)

    0 讨论(0)
  • 2020-12-19 09:58

    May be these article will help:

    • Fill DataSet with multiple Tables and update them with DataAdapter
    • C# Dataset with multiple tables - OLEDB

    Following official articles also very useful information:

    • Navigating Multiple Related Tables in an ADO.NET Dataset
    • Populating a DataSet from a DataAdapter (ADO.NET)

    Look at the "Populating a DataSet from Multiple DataAdapters" section in above article.

    0 讨论(0)
提交回复
热议问题