Convert DataSet or DataTable to XML

Normally we face this problem where we have lots of data to convert into XML file from DataSet or DatTable  .Because XML file is readable by all languages.

Here I have some sample Snippet for Writing the DataSet or DataTable to XML format.

   DataSet ds = new DataSet();
   using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CON"].ConnectionString))
            {
                con.Open();
                string Query = "select col1,col2 from table ";
                SqlDataAdapter da = new SqlDataAdapter(Query, con);
                da.Fill(ds,"TableName");
                ds.Tables["TableName"].WriteXml("XML File Path");
            }


Hope this help you :-)

Any Suggestion s on this article are welcome :-)

Popular posts from this blog

Exporting to excel from a custom class object using C#.NET

How to hide bootStrap popover when user click(s) outside the popover?

Get the Clicked Cell Value and Column Name of GridView in ASP.NET