2015-02-06 149 views
0

我'嘗試使用下面的代碼SQL Server表導出到XML文件:導出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> 

我需要知道這種格式的名稱是什麼。該格式在ASPxGriveView之內爲XMLDataSource

回答

0

對於要作爲XML屬性導出的每個列,請將DatacolumnColumnMapping屬性設置爲MappingType.Attribute

dataTable = dataSet.Tables["SomeTable"]; 

foreach (DataColumn dc in dataTable.Columns) 
{ 
    dc.ColumnMapping = MappingType.Attribute; 
} 
+0

是......這就是我想要的......謝謝羅伯特...... – JemoGlemo 2015-02-06 21:57:53