Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ColumnMapping Property

DataColumn.ColumnMapping Property

Gets or sets the MappingType of the column.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

public virtual MappingType ColumnMapping { get; set; }

Property Value

Type: System.Data.MappingType
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.

The following example sets the ColumnMapping type property of new DataColumn.

private void AddColumn(DataTable table)
    // Create a new column and set its properties.
    DataColumn column = new DataColumn("column", 
        typeof(int), "", MappingType.Attribute);
    column.DataType = Type.GetType("System.String");
    column.ColumnMapping = MappingType.Element;

    // Add the column the table's columns collection.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
© 2015 Microsoft