You can use
XmlSerialization
.
StringWriter strWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);
xmlWriter.WriteStartElement("RootNode");
// instead of RootNode, you can have the required table name in it.
SqlConnection mySqlConnection;
mySqlConnection = new SqlConnection(sConnection);
mySqlConnection.Open();
XmlReader xmlReader = new SqlCommand("Select * From Table1 FOR XML AUTO, Elements", mySqlConnection).ExecuteXmlReader();
xmlWriter.WriteNode(xmlReader, true);
xmlReader.Close();
xmlWriter.WriteEndElement();
mySqlConnection.Close();
You will have the xml string in strWriter. You can use
XmlSerializer
class.
OR,
You can get help from the below link
http://blogs.msdn.com/b/saurabh_singh/archive/2010/05/11/export-sql-table-records-to-xml-form.aspx[
^]