[ Team LiB ] |
29.3 Collections Reference
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. ExampleThe 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 is similar. SqlDataAdapter da; // ... code to set up the DataAdapter da // map the DataSet table MyOrders to the data source table Orders DataTableMapping dtm = da.TableMappings.Add("Orders", "MyOrders"); // The next three commands remove the mapping just added // remove the table mapping just added, using a reference to the // DataTableMapping object da.TableMappings.Remove(dtm); // use RemoveAt to remove the DataTableMapping s da.TableMappings.RemoveAt(0); // use RemoveAt with the data source table name da.TableMappings.RemoveAt("Orders"); // use Clear method to remove all mappings da.TableMappings.Clear(); NotesA mapping is created by adding a DataTableMapping object to the DataTableMappingCollection collection. This maps a table in the data source to a table with different name in the DataSet. Each DataTableMapping object contains a DataColumnMappingCollection object that is accessed through its ColumnMappings property. The collection controls how columns in the data source are mapped to DataColumn objects in the DataTable. The column mapping applies only for the table mapped by the DataTableMapping. A column mapping is created by adding a DataColumnMapping object to the DataColumnMappingCollection collection. This maps a column in the data source to a column with a different name in the DataSet. Both table and column mappings can be used by the Fill( ) and FillSchema( ) methods when retrieving data, and by the Update( ) method when submitting DataSet changes back to the data source. The Fill( ) method always uses mapping information if it's available; the FillSchema( ) method lets you choose whether to use the mapping information. If incoming data source table and column names don't match DataSet object names, and mapping isn't performed, the MissingMappingAction property of the DataAdapter determines what action is taken when data is retrieved using the Fill( ) method. Similarly, if incoming data source table and column names don't match DataSet object names, and mapping isn't performed, the MissingSchemaAction property of the data adapter determines what action is taken when the schema is retrieved using the FillSchema( ) or Fill( ) method. DataTableMappingCollectionThe commonly used public properties of the DataTableMappingCollection are listed and described in Table 29-8.
The commonly used public methods of the DataTableMappingCollection are listed and described in Table 29-9.
DataTableMapping classThe commonly used public properties of the DataTableMapping class are listed and described in Table 29-10.
The commonly used public methods of the DataTableMapping class are listed and described in Table 29-11.
DataColumnMappingCollectionThe DataColumnMappingCollection is returned by the ColumnMappings collection property of the TableMappings class. It maps the names of columns in the DataSet to columns in the data source with different names. The commonly used public properties of the DataColumnMappingCollection are listed and described in Table 29-12.
The commonly used public methods of the DataColumnMappingCollection are listed and described in Table 29-13.
DataColumnMapping classThe commonly used public properties of the DataColumnMapping class are listed and described in Table 29-14.
The commonly used public methods of the DataColumnMapping class are listed and described in Table 29-15.
|
[ Team LiB ] |