Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii,

how can i export dataset with 3 datatable in excel.
i want all three datatable from dataset are export in each diffrent sheet of excel using c#.
Posted

1 solution

C#
 DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();

dt = ds.Tables[0];
dt1 = ds.Tables[1];
dt2 = ds.Tables2];
//for first file
        string attachment = "attachment; filename=file1.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        Response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(tab + dr[i].ToString());
                tab = "\t";
            }
            Response.Write("\n");
        }
// write same code for second and third file with dt1 and dt2 data tables
 Response.End();
 
Share this answer
 
v2
Comments
Ankur Ramanuj 18-Mar-14 8:52am    
its not print these 3 three table in three sheets...

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