Write data in database table to XML file : Database to XML : Database C# Source Code


Custom Search

C# Source Code » Database » Database to XML »

 

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

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

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

            ds.WriteXml(@"employee.xml");
         } catch(Exception e) {
            Console.WriteLine("Error: " + e);
         } finally {
            conn.Close();
         }
      }
   }


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Database
» Database to XML