DataColumn.ColumnMapping 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定欄位的 。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的型態性質。
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 a DataSet 被儲存為 XML 文件時,a 如何DataColumn映射。
例如,若 a 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。