TableAdapterManager Overview

The TableAdapterManager is a new component in Visual Studio 2008 that builds upon existing data features (typed datasets and TableAdapters) and provides the functionality to save data in related data tables. The TableAdapterManager uses the foreign-key relationships that relate data tables to determine the correct order to send the Inserts, Updates, and Deletes from a dataset to the database without violating the foreign-key constraints (referential integrity) in the database.

Foreign-key constraints are the consistency rules in a database that control the behavior of Inserting, Updating, and Deleting related records. It is foreign-key constraints that prevent parent records from being deleted while related child records in another table still exist.

The overall process of saving data in related data tables by using a TableAdapterManager is called Hierarchical Update.

Saving modified data from related data tables is somewhat more complex than saving data from a single table. This is because the Insert, Update, and Delete commands for each related table have to be executed in a specific order to avoid violating the foreign-key constraints that are defined in the database. For example, consider an order entry application with which you can manage both new and existing customers and orders. If you have to delete an existing customer record, you must first delete all of that customer's orders. If you are adding a new customer record (with an order), you must first insert the new customer record before inserting that customer's orders because of the foreign key constraints that are in the tables. As these examples show, you have to extract specific subsets of data and send the updates (Inserts, Updates, and Deletes) in the correct order to maintain referential integrity and avoid conflicts with the foreign-key constraints in the database.

Creating TableAdapterManagers

By default, a TableAdapterManager class is generated when you create a typed-dataset in a project. More specifically, it is the value in the Hierarchical Update property of a dataset that determines whether a TableAdapterManager is created. If Hierarchical Update is set to True, a TableAdapterManager is created; Hierarchical Update is set to False, a dataset that does not contain a TableAdapterManager is created. For more information, see How to: Enable and Disable Hierarchical Update.


By default, datasets added to projects created in earlier versions of Visual Studio have the Hierarchical Update property set to False. This means that hierarchical update is disabled and a TableAdapterManager is not created. For information about adding a TableAdapterManager to an existing dataset, see How to: Implement Hierarchical Update in Existing Visual Studio Projects.

TableAdapterManager Reference

The TableAdapterManager class is not part of the .NET Framework. Therefore, you cannot look it up in the documentation. It is created at design time as part of the dataset creation process.

The following are the frequently used methods and properties of the TableAdapterManager class:



UpdateAll method

Saves all data from all data tables.

BackUpDataSetBeforeUpdate property

Boolean. Determines whether to create a backup copy of the dataset before executing the TableAdapterManager.UpdateAll method.

tableNameTableAdapter property

Represents a TableAdapter. The generated TableAdapterManager contains a property for each TableAdapter it manages. For example, a dataset with a Customers and Orders table is generated with a TableAdapterManager that contains CustomersTableAdapter and OrdersTableAdapter properties.

UpdateOrder property

Controls the execution order of the individual Insert, Update, and Delete commands. Set this to one of the values in the TableAdapterManager.UpdateOrderOption enumeration.

By default, the UpdateOrder is set to InsertUpdateDelete. This means that Inserts are performed for all tables in the dataset, then Updates are performed for all tables in the dataset, and then Deletes are performed for all tables in the dataset. For more information, see How to: Set the Order When Performing a Hierarchical Update.

See Also


Walkthrough: Saving Data from Related Data Tables (Hierarchical Update)

Walkthrough: Creating a Simple Data Application


TableAdapter Overview

Other Resources

Hierarchical Update

Saving Data