Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
Hi,

I have data table in that table have a data that data will be convert in to xml format like
inside tag

example

XML
<CPSMSStateSchemeMapping>
             <StateCode>27</StateCode>
             <FinancialYear>2013</FinancialYear>
             <DepartmentCode>G</DepartmentCode>
             <BudgetCode>0040000000000</BudgetCode>
             <StateSchemeCode>24016241</StateSchemeCode>
             < CPSMSSchemeCode>0404</CPSMSSchemeCode >
            <CreatedDate >22/03/2013</CreatedDate>
  </CPSMSStateSchemeMapping>
Posted
Comments
Tejas Vaishnav 29-Jan-14 2:07am    
can you provide your sample data ..

Hi,

Here is the solution.

C#
// By using this method we can convert datatable to xml
public string ConvertDatatableToXML(DataTable dt)
{
MemoryStream str = new MemoryStream();
dt.WriteXml(str, true);
str.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(str);
string xmlstr;
xmlstr = sr.ReadToEnd();
return (xmlstr);
}



Just pass the Datatable as the parameter to this method you will be getting data in xml format.
 
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