Name

TableMappings

Synopsis


DataTableMappingCollection dtmc = DataAdapter.TableMappings;

Accesses a collection of DataTableMapping objects that map the data source table names to DataSet table names. This allows different table names to be used during change reconciliation. An empty collection is returned if no mappings exist.

Example

The following example shows how to set up a TableMapping and a ColumnMapping:

SqlDataAdapter da;



// ... code to set up the data adapter



// map the DataSet table MyOrders to the data source table Orders

DataTableMapping dtm = da.TableMappings.Add("Orders", "MyOrders");



// map the DataSet column MyOrderID (in the DataSet MyOrders table)

// to the data source column OrderID (in the data source Orders table)

dtm.ColumnMappings.Add("MyOrderID", "OrderID");

The DataTableMappingCollection and DataColumnMappingCollection collections have an AddRange( ) method that allows an array of mappings to be added in a single statement, as shown in the following example:

// map the CustomerID and EmployeeID columns from the data source

dtm.ColumnMappings.AddRange(new DataColumnMapping[] {

    new DataColumnMapping("MyCustomerID", "CustomerID"),

    new DataColumnMapping("MyEmployeeID", "EmployeeID")});

Mappings can be removed from both the DataTableMappingCollection and DataColumnMappingCollection objects using the Remove( ), RemoveAt( ), or Clear( ) methods. The following example demonstrates using these methods with the DataTableMappingCollection; using the methods with the DataColumnMappingCollection ...

Get ADO.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.