System.Data.Common Namespace
Represents the mapping between a table in a data source and its linked DataTable in a DataSet.
A DataTableMapping provides a master mapping between a table in the data source, and a DataTable that contains the results of the query issued against the data source. This class is used by a DataAdapter when populating a DataSet.
A DataTableMapping enables you to use table names in a DataSet that are different from those in the data source. The DataAdapter uses the mapping to match the tables when reconciling changes made to either the data source or the DataSet.
The DataTableMapping name can be passed in place of the DataTable name when using the Fill method of a DataAdapter. For more information, see Setting Up DataTable and DataColumn Mappings.
The following example shows how to add DataTableMapping objects to the TableMappings collection of an SqlDataAdapter, and display a list of those mapped source tables.
void ShowTableMappings ( SqlDataAdapter myAdapter ) {
DataTableMappingCollection myTables = myAdapter.TableMappings;
myTables.Add ( "Categories", "DataCategories" );
myTables.Add ( "Orders", "DataOrders" );
myTables.Add ( "Products", "DataProducts" );
string myMessage = "Table Mappings:\n";
for ( int i=0; i < myTables.Count; i++ ) {
myMessage += i.ToString ( ) + " " +
myTables [ ].ToString ( ) + "<br>";
}
Response.Write ( myMessage );
}
Public Sub ShowTableMappings ( Dim myAdapter As SqlDataAdapter )
Dim myTables As DataTableMappingCollection = myAdapter.TableMappings;
myTables.Add ( "Categories", "DataCategories" )
myTables.Add ( "Orders", "DataOrders" )
myTables.Add ( "Products", "DataProducts" )
Dim myMessage As String = "Table Mappings:" + ControlChars.Cr
Dim i As Integer
For i = 0 To myTables.Count - 1
myMessage = myMessage & i.ToString ( ) & " " & _
myTables ( i ).ToString ( ) & ControlChars.Cr
Next i
Response.Write ( myMessage )
End Sub |
|
C# |
VB |
DataTableMappingCollection DataColumnMapping DataColumnMappingCollection