Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear,
I need to export 1000000 records in excel but it gives out of memory exception.

Please find the below code which I used in the exporting record it works well for 3.5 lacks record
C#
Response.ContentType = "application/vnd.ms-excel";
       string FileName = "PoliciesDetailsForBranch";
       Response.AppendHeader("content-disposition", "attachment; filename=" + FileName + ".xls");
       GridView gv = new GridView();
       this.EnableViewState = false;
       gv.DataSource = (DataTable)dt;
       gv.DataBind();
       this.ClearControls(gv);
       System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(Response.Output);
       gv.RenderControl(hw);
       Response.End();

Please help me to overcome with this issue.
Posted
Updated 27-Sep-10 21:29pm
v4
Comments
Hiren solanki 28-Sep-10 2:25am    
added pre tag for code visibility.
Dalek Dave 28-Sep-10 3:29am    
Minor Edit for Grammar.
voloda2 28-Sep-10 4:16am    
Did you try opening such amount in data in excel? I don't believe you will succeed...
E.F. Nijboer 28-Sep-10 5:57am    
You might want to add a flush now and then because that amount of records will generate a lot of data. The server won't be happy about keeping it all into memory for just a single client.

1 solution

A good example already given on codeproject site, how to export data to multiple excel sheet.


Export DataSet to Multiple Excel Sheets
 
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