Place root node on xmltextwriter

M

Martin

Hi,

I am retriving data from sql server using the xml raw clause and an
xmltextwriter.

this is working out fine except the xml raw clause does not put a root node
on the xml that is returned from sql server and subsequently an xmldocument
can't be created from the xmltextwriter as there is no root element.

however if the xml raw query returns only a single row then there is a root
element and everything works just fine.

my question is how do I attach a root element to an xmltextwriter.

many thanks in advance.

cheers

martin.



SqlConnection conn = new SqlConnection(
"server=.;uid=pubsUser;password=pubsUser;database=pubs");

SqlCommand cmd = new SqlCommand(
"select top 1 * from authors for xml raw", //<==== does not work
when "top 1" is removed as there is no root node
conn);

conn.Open();

XmlTextReader rdr;
rdr = (XmlTextReader)cmd.ExecuteXmlReader();
XmlDocument xml = new XmlDocument();
xml.Load(rdr); <======================will fail if there is not a root
node...
xml.Save(Console.Out);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top