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 值。

屬性

範例

下列範例會 ColumnMapping 設定新 DataColumn的 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 檔案時,如何DataColumn對應 DataSet

例如,如果 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 檔案時,如何DataColumnDataSet對應 。

屬性 ColumnMapping 會對應至建構函式自變數 type

適用於

另請參閱