ADO Net C# Tutorial

using System;
using System.Data;
using System.Data.SqlClient;
    class WriteXML
    {
        static void Main(string[] args)
        {
            string connString = @"server = .\sqlexpress;integrated security = true;database = northwind";
            string qry = @"select productname,unitprice from products";
            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, "products");
                ds.WriteXml("table.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }
            finally
            {
                conn.Close();
            } 
        }
    }