Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
4.33/5 (2 votes)
See more:
Hello

I am trying to load data from dataset to excel sheet like this
C#
Excel.ExcelPackage app = new Excel.ExcelPackage();
app.Workbook.Worksheets.Add("Sheet1").Cells["A1"].LoadFromDataTable(uploadDS.Tables[0], true);

Here iam getting error like System.outofmemory exception.

I am uploading to dataset like this:
C#
SqlDataAdapter uploadDA = new SqlDataAdapter(query, uploadCon);
 DataSet uploadDS = new DataSet("UploadDataset");
uploadDA.Fill(uploadDS);


Thanks for any help.
Posted
Updated 26-Nov-13 3:34am
v2
Comments
Ron Beyer 26-Nov-13 9:33am    
So what line do you get the out of memory exception on?
njdcjk 26-Nov-13 9:37am    
app.Workbook.Worksheets.Add("Sheet1").Cells["A1"].LoadFromDataTable(uploadDS.Tables[0], true);
Adam Zgagacz 26-Nov-13 9:40am    
Most likely query to the database is producing more than memory can handle. Can you investigate first what your query produces?
thatraja 26-Nov-13 10:13am    
How many rows & columns?
Herman<T>.Instance 26-Nov-13 10:22am    
are you using EPPLUS? Write to a FILEstream in stead of a Memorystream

How many rows and columns are you trying to stuff into Excel?? Excel cannot hold an infinite amount of data. You probably really are running the machine out of memory or you're Exceeding the amount of data that Excel can hold in a single sheet/workbook.
 
Share this answer
 
Comments
njdcjk 26-Nov-13 23:49pm    
Iam jst using 20k records
Dave Kreskowiak 27-Nov-13 7:53am    
OK, now how much data is in each row?? You have to figure out what the worst possible case is for each row and multiply that by the number of records.
In past I have answered similar question, check it out.
best way to use .net Datatable with a huge data[^]
Also check this for excel limitations
Exporting to Microsoft Excel[^]
 
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