Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
I want to transfer datas stored in a datatable to xml format..which should not be a document.should be in a string format,and from that string i have to regain the datas in datatable in which type its stored there...How can i do this using textwriter.Help me please...
Thanks in advance..
swathi.
Posted
Updated 17-Jan-13 19:26pm
v2

Normally, you would store your data from the datatable in the database directly, without using XML in between. But if you, for whatever reason, want to have that, try serialization with the SoapFormatter[^] class.
 
Share this answer
 
Hi,

Please refer the below link, you might find your solution.

http://sandit27.wordpress.com/2009/01/18/how-to-convert-datatable-to-xml-in-c/[^]
 
Share this answer
 
C#
StringBuilder stringBuilder = new StringBuilder(string.Empty);
            StringWriter stringWriter = new StringWriter(stringBuilder);
            DataSet dsMemmoryList = new DataSet();
            dsMemmoryList.Tables.Clear();
            DataTable dtMemmoryList = new DataTable();
            dtMemmoryList.Columns.Add("RowNumber");
            dtMemmoryList.Columns.Add("AccessionNo");
            DataRow drLoan;
            int rowNumber = 1;
            foreach (string accession in accessionCollecion)
            {
                drLoan = dtMemmoryList.NewRow();
                drLoan[0] = rowNumber;
                drLoan[1] = accession;
                dtMemmoryList.Rows.Add(drLoan);
                rowNumber++;
            }
            dsMemmoryList.Tables.Add(dtMemmoryList);
            dsMemmoryList.WriteXml(stringWriter, XmlWriteMode.WriteSchema);
            string string1 = "\\\"";
            string string2 = "\"";
            string xml = Convert.ToString(stringBuilder);
            xml = xml.Replace(string1, string2);
            return xml;
 
Share this answer
 
v2

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