Dim oCon As SqlConnection = New SqlConnection("... your connection string ...")
Dim daCmd As SqlDataAdapter = New SqlDataAdapter("... your select command ...", oCon)
Dim dsTest As DataSet = New DataSet
Dim theError As String
Try
oCon.Open()
daCmd.Fill(dsTest, "Test")
Dim doc As XMLDataDocument = New XMLDataDocument(dsTest)
Dim writer As XMLTextWriter = New XMLTextWriter("C:\inetpub\[URL unfurl="true"]wwwroot\MyDocs\test.xml",[/URL] nothing)
writer.Formatting = Formatting.Indented
doc.Save(writer)
writer.Close()
Catch ex As Exception
theError=ex.Message()
Finally
oCon.Close()
End Try