System.Data Namespace DataColumn Class
Sets or retrieves the MappingType of the column.
Script |
DataColumn.ColumnMapping [ = enumValue ] |
The property is read/write with no default value.
The ColumnMapping property determines how a DataColumn is mapped when a DataSet is saved as an XML document using the WriteXml method.
For example, if a DataColumn is named "customerID," and its ColumnMapping property is set to MappingType.Element, the column value will produce the following XML:
<Customers>
<customerID>ALFKI </customerID>
...
</Customers>
<Orders>
<OrderID>12345</OrderID>
<customerID>ALFKI </customerID>
...
</Orders>
However, if the same column is mapped to MappingType.Attribute, the following XML is produced:
<Customers customerID="ALFKI" ... more attributes ... >
<Order orderID="1234" ... more attributes ... />
<Order orderID="1234" ... more attributes ... />
... more orders for this customer
</Customers>
Use the DataColumn constructor that contains the type argument to specify how the DataColumn is mapped when its DataSet is transformed to an XML document.
The ColumnMapping property corresponds to the constructor argument type, that decides whether a DataColumn is mapped as an XML attribute when a DataSet is transformed into XML.
The following example sets the ColumnMapping type property of new DataColumn.
private void AddColumn ( DataTable myTable ) {
// create a new column and set its properties.
DataColumn myColumn = new DataColumn ( "myColumn" );
myColumn.DataType = Type.GetType ( "System.String" );
myColumn.ColumnMapping = MappingType.Element;
// add the column the table's columns collection.
myTable.Columns.Add ( myColumn );
}
Private Sub AddColumn ( myTable As DataTable )
' create a new column and set its properties.
Dim myColumn As DataColumn = New DataColumn ( "myColumn" )
myColumn.DataType = Type.GetType ( "System.String" )
myColumn.ColumnMapping = MappingType.Element
' add the column the table's columns collection.
myTable.Columns.Add ( myColumn )
End Sub |
|
C# |
VB |
DataColumn Members