"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Sunday, November 20, 2011

Exporting an sql table to XML

Hi *.*,
To export data first it should be hold in a Dataset or Datatable or else where we can loop(Here i used a dataset).
Code:


DataSet ds = new DataSet();
string _con = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]
.ToString();
System.Data.SqlClient.SqlConnection constr = new System.Data.SqlClient.SqlConnection(_con);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("Select * from Cities", constr);
da.Fill(ds);
ds.WriteXml(@"c:\Cities.xml", XmlWriteMode.WriteSchema);

If u had any trouble just ask, Happy to help u :) 
Stay Tune... 
Have a nice day... 'N happy Coding :)

No comments: