Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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 17-Jan-13 20:12pm
Edited 17-Jan-13 20:26pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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/[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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;
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 520
1 Mathew Soji 335
2 BillWoodruff 260
3 OriginalGriff 215
4 Afzaal Ahmad Zeeshan 188
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100