如何使用 vb.net 从数据库创建 XML 文件正如我所尝试的,我只得到了创建的根元素,而不是来自数据库的任何数据,我的代码是:
<% @Import Namespace="System" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.xml" %>
<% @Import Namespace="System.Data.SqlClient" %>
<Script runat="server">
Sub Page_Load
Dim connectionString As String
Dim connection As SqlConnection
Dim adapter As SqlDataAdapter
Dim ds As New DataSet
Dim sql As String
connectionString =// my connection string///
connection = New SqlConnection(connectionString)
sql = "select * from jb_jobs where city='Los Angeles' "
connection.Open()
adapter = New SqlDataAdapter(sql, connection)
adapter.Fill(ds)
connection.Close()
If IO.File.Exists("product.xml") = False Then
Dim settings As New XmlWriterSettings()
settings.Indent = True
Dim XmlWrt As XmlWriter = XmlWriter.Create("c:/xmlfiles/product.xml", settings)
XmlWrt.WriteStartDocument()
XmlWrt.WriteComment("XML Database.")
XmlWrt.WriteStartElement("source")
XmlWrt.WriteStartElement("jobs")
XmlWrt.WriteEndElement()
XmlWrt.WriteEndDocument()
XmlWrt.Close()
End If
End Sub
</script>
我得到的输出只是一个 XML 文件,它仅使用上述根元素创建,而不是来自数据库的数据。
如何从数据库中获取数据并形成 XML 文件?