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 :-)

Comments

Popular posts from this blog

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

Why Dispose() is preferred than Finalize() for Un-Managed Resources in .NET?

How to apply watermark to the textbox and dropdownlist?