O'Reilly logo

ADO.NET in a Nutshell by Bill Hamilton, Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required