Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one tell me how to export data from dataset to excel file ?

C#
string s = System.Configuration.ConfigurationSettings.AppSettings.Get("Conn");
            SqlConnection connection = new SqlConnection(s);
            connection.Open();
            SqlCommand cmd = new SqlCommand("ssp_AgriPrint");
            cmd.Parameters.AddWithValue("@cSerialNo", textBox1.Text);
            
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();


I just want to export dataset data ds to excel file
Posted
Updated 14-Aug-13 1:18am
v2

Check with these blogs links

1.http://kishsharmasoftcode.blogspot.in/[^]

2.http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-excel-or.html[^]
For any doubt please put comments.
welcome
 
Share this answer
 
v2
HI,

Refer the following solution:

How to export excel from dataset or datatable in c#?

Please use to google before posting the question...

Thanks
 
Share this answer
 
1) Import-export-dataset-xls.[^]

2)Snippet From Export-dataset-to-excel-in-c[^]
C#
public static void CreateWorkbook(DataSet ds, String path)
 {
    XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
    XslTransform xt = new XslTransform();
    StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), "Excel.xsl"));
    XmlTextReader xRdr = new XmlTextReader(reader);
    xt.Load(xRdr, null, null);

   StringWriter sw = new StringWriter();
    xt.Transform(xmlDataDoc, null, sw, null);

   StreamWriter myWriter = new StreamWriter (path + "\\Report.xls");
    myWriter.Write (sw.ToString());
    myWriter.Close ();
 }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900