Hi @peter liles ,
The code to convert DataTable to xml file can be set as follows:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim ConString As String = ConfigurationManager.ConnectionStrings("MenuTest").ConnectionString
Dim CmdString As String = "SE LECT * FROM MenuTest"
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim sda As SqlDataAdapter
Dim dt As DataTable
Using CSharpImpl.__Assign(con, New SqlConnection(ConString))
cmd = New SqlCommand(CmdString, con)
con.Open()
dt = New DataTable("Menus")
sda = New SqlDataAdapter(cmd)
sda.Fill(dt)
dt.WriteXml("***")
con.Close()
End Using
End Sub
You can also add a data table to a dataset and call GetXml() on the dataset.
In addition to this dataset, it is equipped with WriteXml() and ReadXml() for writing/reading XML directly into a file path or stream.
Dim ds As DataSet = New DataSet()
ds.Tables.Add(dt1)
ds.Tables.Add(dt2)
Dim dsXml As String = ds.GetXml()
Using fs As StreamWriter = New StreamWriter(xmlFile) // XML File Path
ds.WriteXml(fs)
End Using
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.