How to convert datatable to xml in c sharp

Using below example you can convert dataset or data table into XML format. Please find below example for reference.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace convert_datatable_to_xml
    class Program
        static void Main(string[] args)
            //creating datatable
            DataTable dt = new DataTable("Employ");
            //adding columns to datatable

            //adding rows to datatable
            dt.Rows.Add("1", "ranga");
            dt.Rows.Add("2", "rajesh");

            //creating dataset
            DataSet ds = new DataSet("Employ_Details");
            //adding datatable to dataset
            //showing dataset value into XML format. 

Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar