DataColumn.ColumnMapping 属性

定义

获取或设置列的 MappingType

public:
 virtual property System::Data::MappingType ColumnMapping { System::Data::MappingType get(); void set(System::Data::MappingType value); };
public virtual System.Data.MappingType ColumnMapping { get; set; }
[System.Data.DataSysDescription("DataColumnMappingDescr")]
public virtual System.Data.MappingType ColumnMapping { get; set; }
member this.ColumnMapping : System.Data.MappingType with get, set
[<System.Data.DataSysDescription("DataColumnMappingDescr")>]
member this.ColumnMapping : System.Data.MappingType with get, set
Public Overridable Property ColumnMapping As MappingType

属性值

MappingType 值之一。

属性

示例

以下示例设置 ColumnMappingDataColumn的 type 属性。

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.
    table.Columns.Add(column);
}
Private Sub AddColumn(table As DataTable )
    ' Create a new column and set its properties.
    Dim column As New DataColumn("ID", _
        Type.GetType("System.Int32"), "", MappingType.Attribute)
    column.DataType = Type.GetType("System.String")
    column.ColumnMapping = MappingType.Element

    ' Add the column the table's columns collection.
    table.Columns.Add(column)
End Sub

注解

属性ColumnMapping确定在使用 WriteXml 方法将 保存为 XML 文档时DataSet如何DataColumn映射 。

例如,如果 DataColumn 名为“customerID”,并且其 ColumnMapping 属性设置为 MappingType.Element,则列值将生成以下 XML:

<Customers>
 <customerID>ALFKI</customerID>
......
 </Customers>
 <Orders>
 <OrderID>12345</OrderID>
 <customerID>ALFKI</customerID>
......
 </Orders>

但是,如果将同一列映射到 MappingType.Attribute,则会生成以下 XML:

<Customers customerID="ALFKI"........more attributes.....>
 <Order orderID="1234"....more attributes..../>
 <Order orderID="1234"....more attributes..../>
...... More orders for this customer
 </Customers>

DataColumn使用包含 参数的type构造函数指定在转换为 XML 文档时DataSet如何DataColumn映射 。

属性 ColumnMapping 对应于构造函数参数 type

适用于

另请参阅