Better way to extract data from an SQL Database in XML format?
Posted on 2007-10-18
I've been able to do what i want in ASP.NET (get records from a DB in XML format), but i would like to know if there's a better (shorter) way. I thought that "reader.toString()" would do the whole job, but i had to do it by itteration:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dbOOO As SqlConnection
Dim sb As New StringBuilder()
Dim cmdBYSSelect As SqlCommand
Dim reader As XmlReader
dbOOO = New SqlConnection("my connection info here")
cmdBYSSelect = New SqlCommand("SELECT * FROM myTable FOR XML AUTO, XMLDATA", dbOOO)
reader = cmdBYSSelect.ExecuteXmlReader()
sb.AppendLine("<?xml version=""1.0"" encoding=""utf-8"" ?>" & vbCrLf)
sb.AppendLine("<TopLevel>" & vbCrLf)
Do While reader.ReadState <> System.Xml.ReadState.EndOfFile
Any idea how i could optimize that?