如何使用vb.net從數據庫創建XML文件 正如我試過,我只得到了創建的根元素,而不是數據庫中的任何數據,我的代碼是:如何在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文件?
我在創建XML文件時沒有任何問題,但問題是從數據庫中檢索值並將其保存到XML文件 – ammukarthi