Write data in database table to XML file : Database to XML « Database ADO.net « C# / C Sharp

Write data in database table to XML file

using System;
using System.Data;
using System.Data.SqlClient;

   class WriteXML {
      static void Main(){
         string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
         string qry = @"select * from employee";
         SqlConnection conn = new SqlConnection(connString);

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand(qry, conn);

            DataSet ds = new DataSet();   
            da.Fill(ds, "employee");

         } catch(Exception e) {
            Console.WriteLine("Error: " + e);
         } finally {


Related examples in the same category

1.How to write and read XML files
2.Use the ExecuteXmlReader() method to run a SELECT statement that returns XML