0

我正在尝试使用以下代码将 SQL Server 表导出到 XML 文件:

Dim ds As New Data.DataSet("MyData")   
Dim QueryStr As String = "Select * from Inventory" 
Dim ConnectionStr as String = "data source=SQLSERVER\ITDB;integrated..."
Dim da As New System.Data.SqlClient.SqlDataAdapter(QueryStr,ConnectionStr)
da.Fill(ds)
da.Dispose()
ds.WriteXml("c:\output.xml")

XML 文件的输出格式如下:

<MyData>
<Table>
  <IPAddress>192.168.0.193</IPAddress>
  <UserName>Admin</UserName>
  <Location>Store</Location>
</Table>
</MyData>

我想将 XML 文件格式更改为:

<MyData>
<Table IPAddress="192.168.0.193" UsersName="1001" Location="Store" />
</MyData>

我需要知道这种格式的名称是什么。这种格式XMLDataSourceASPxGriveView.

4

1 回答 1

0

为要导出为 XML 属性的每一列设置Datacolumn ColumnMapping属性。MappingType.Attribute

dataTable = dataSet.Tables["SomeTable"];

foreach (DataColumn dc in dataTable.Columns)
{
    dc.ColumnMapping = MappingType.Attribute;
}
于 2015-02-06T21:48:18.580 回答