我有具体问题,目前没有答案.. :(
我必须使用 SQL Server 表中的这种结构创建一个用于导出的 xml 文件...
<?xml version="1.0" encoding="UTF-8"?>
<DATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="t_SR.xsd">
<t_SR>
<SR_COMP_ID>9002</SR_COMP_ID>
<SalesRepresentative>
<SR_ID>19</SR_ID>
<SR_Name>Jan Kowalski</SR_Name>
<SR_Type>RSM</SR_Type>
</SalesRepresentative>
</t_SR>
</DATA>
我试图用下面的代码来做到这一点:
Imports System.Xml
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connetionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim ds As New DataSet("DATA")
Dim sql As String
connetionString = "Data Source=<server hostname>;Initial Catalog=<database name>;User ID=<username>;Password=<password>
connection = New SqlConnection(connetionString)
sql = "select id as SR_ID,name as SR_Name,SR_Type from dbo.users where not SR_TYPE='Operator';"
Try
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds, "SalesRepresentative")
ds.WriteXml("C:\SR.xml")
MsgBox("Done")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
但是代码会生成这个(出于已知原因:)):
<?xml version="1.0" standalone="true"?>
<DATA>
<SalesRepresentative>
<SR_ID>3</SR_ID>
<SR_Name>Name</SR_Name>
<SR_Type>GM</SR_Type>
</SalesRepresentative>
<DATA>
如何添加encoding = UTF-8
和删除standalone=yes
?和 xsd 模式的线?
我怎样才能把块SR_COMP_ID
?