ColumnMapping Property

DataColumn.ColumnMapping Property

Gets or sets the MappingType of the column.

[Visual Basic]
Public Overridable Property ColumnMapping As MappingType
public virtual MappingType ColumnMapping {get; set;}
public: __property virtual MappingType get_ColumnMapping();
public: __property virtual void set_ColumnMapping(MappingType);
public function get ColumnMapping() : MappingType;
public function set ColumnMapping(MappingType);

Property Value

One of the MappingType values.


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:


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

Use the DataColumn constructor that contains the type argument to specificy how the DataColumn is mapped when its DataSet is transformed to an XML document.

The ColumnMapping property corresponds to the constructor argument type.


[Visual Basic, C#, C++] The following example sets the ColumnMapping type property of new DataColumn.

[Visual Basic] 
Private Sub AddColumn(myTable As DataTable )
    ' Create a new column and set its properties.
    Dim myColumn As DataColumn = New DataColumn("myColumn", Type.GetType("System.Int32"), "", MappingType.Attribute)
    myColumn.DataType = Type.GetType("System.String")
    myColumn.ColumnMapping = MappingType.Element
    ' Add the column the table's columns collection.
 End Sub

private void AddColumn(DataTable myTable){
    // Create a new column and set its properties.
    DataColumn myColumn = new DataColumn("myColumn", typeof(int), "", MappingType.Attribute);
    myColumn.DataType = Type.GetType("System.String");
    myColumn.ColumnMapping = MappingType.Element;
    // Add the column the table's columns collection.

void AddColumn(DataTable* myTable){
    // Create a new column and set its properties.
    DataColumn* myColumn = new DataColumn(S"myColumn", __typeof(int), S"", MappingType::Attribute);
    myColumn->DataType = Type::GetType(S"System.String");
    myColumn->ColumnMapping = MappingType::Element;
    // Add the column the table's columns collection.

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataColumn Class | DataColumn Members | System.Data Namespace

© 2015 Microsoft