ColumnMapping
MappingType columnMapping = DataColumn.ColumnMapping; DataColumn.ColumnMapping = columnMapping;
Gets or sets the MappingType
for the column.
The following example shows how to set the
MappingType
for a column so that the data for the
column is output as an attribute.
DataColumn col = new DataColumn("MyColumn", typeof(System.String)) col.ColumnMapping = MappingType.Attribute;
The MappingType
determines how the column data is
written when it is saved to XML using the WriteXml
method of the DataSet
. It can be set to one of the
MappingType
enumeration values described in
Table 24-3.
Using the first record in the Customers
table in
Northwind as an example, if the ColumnMapping
for
each column is set to Element
, the following XML
is produced:
<Customers> <CustomerID>ALFKI</CustomerID> <CompanyName>Alfreds Futterkiste</CompanyName> ... <Fax>030-0076545</Fax> </Customers>
If, on the other hand, the ColumMapping
for each
column is set to Attribute
, the following XML is
produced:
<Customers CustomerID=" ALFKI" CompanyName=" Alfreds Futterkiste" ... Fax="030-0076545" />
The ColumnMapping
property must be set explicitly
on each column to set it to a value other than the default value.
The default value for ColumnMapping
is
Element
.