Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get XML representation of SQL server database ?
for example user will type
and the result is XML based on the database. example:


I dont want the results to show in xml GUI like control, I want it pure XML like this


thanks in adanced

Share this answer
You can use XQuery for xml operation,

Check the url,[^]

Share this answer
You can use XmlSerialization.

StringWriter strWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);

// instead of RootNode, you can have the required table name in it.

SqlConnection mySqlConnection;
mySqlConnection = new SqlConnection(sConnection);

XmlReader xmlReader = new SqlCommand("Select * From Table1 FOR XML AUTO, Elements", mySqlConnection).ExecuteXmlReader();
xmlWriter.WriteNode(xmlReader, true);



You will have the xml string in strWriter. You can use XmlSerializer class.


You can get help from the below link[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900