473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Export GridView to Excel cause System.OutOfMemoryException - ASP.NET VB

15
Hello everyone,

I want to export GridView (25000 records) to Excel. But i got an error message like : System.OutOfMemoryException was Thrown.

But i need to export the records (even more than 25000 records) to excel

How to solve this ?
Oct 27 '08 #1
11 12558
ulai
15
Hello everyone,

I want to export GridView (25000 records) to Excel. But i got an error message like : System.OutOfMemoryException was Thrown.

But i need to export the records (even more than 25000 records) to excel

How to solve this ?
Oct 27 '08 #2
kenobewan
4,871 Expert 4TB
Why don't you create the excel spreadsheet directly from the database? Why would you need to create a spreadsheet that is 25000 records long, how useful is that spreadsheet going to be?
Oct 27 '08 #3
Curtis Rutland
3,256 Expert 2GB
Well, you're trying to load more data than you have RAM. That's why you would get an OutOfMemoryException.

Also, that is getting close to Excel's row limit, I think.
Oct 27 '08 #4
ulai
15
Thanks for replying

For the reason is I want to list the data with the spesific criteria that was given. And for 25000 records is just a matter of the USER BAD-HABIT that i want to handle.

And is it depend on memory that i have ?
my memory is 2004 MB RAM, and i checked the usage of memory is so low
Oct 28 '08 #5
kenobewan
4,871 Expert 4TB
If it is a user bad habit you are wanting to handle, then you either need to set a timeout for the transaction and/or enable custom error handling in your application.
Oct 28 '08 #6
jhardman
3,406 Expert 2GB
Hello everyone,

I want to export GridView (25000 records) to Excel. But i got an error message like : System.OutOfMemoryException was Thrown.

But i need to export the records (even more than 25000 records) to excel

How to solve this ?
Would you be opposed to exporting it as a csv or xml file (either of which are compatible with excel)? I know XML files are virtually limitless, and csv files can be written one line at a time - this wouldn't use much system memory. Now that I think about it, to get through that many records, you might need to add it a row at a time, just because of size restrictions.

BTW, in ASP we usually don't talk about GridViews, that is a term used in ASP.NET. Are you using ASP.NET (file extension .aspx) or ASP (file extension .asp)?

Jared
Oct 28 '08 #7
ulai
15
If it is a user bad habit you are wanting to handle, then you either need to set a timeout for the transaction and/or enable custom error handling in your application.
I am new in asp.net. And i don't know how to do that. Would you tell me how to do that ?
Oct 29 '08 #8
ulai
15
I got this code (in .aspx) to export Table into Excel :

Expand|Select|Wrap|Line Numbers
  1. If (Not (gridExport.HeaderRow) Is Nothing) Then
  2.     virTable.Rows.Add(gridExport.HeaderRow)
  3. End If
  4.  
  5. For i = Val(txtPageFrom.Text) To Val(txtPageTo.Text)
  6.                 gridExport.PageIndex = i
  7.                 gridExport.DataBind()
  8.  
  9.                 For Each row As GridViewRow In gridExport.Rows
  10.                     virTable.Rows.Add(row)
  11.                 Next
  12.  
  13.                 If (Not (gridExport.FooterRow) Is Nothing) Then
  14.                     virTable.Rows.Add(gridExport.FooterRow)
  15.                 End If
  16. Next
  17.  
  18. virTable.RenderControl(oHtmlTextWriter)
  19. Response.Write(oStringWriter)
  20. Response.End()
Is it what you mean ?
Or i should append row into excel. If so, would you tell me how to do it ?
Oct 29 '08 #9
jhardman
3,406 Expert 2GB
Moved your thread to the .NET forum - this spot has a lot of experts that are better than me at this type of thing. If they don't give you a response in a day or two we'll ask a couple of them to help out.

It looks like your code puts all of the data in a temporary table before saving it - and it is the temporary table that is probably having the problem since Excel has a limit of something like 65,000 rows. Instead of forming a temporary table, we should be trying to add each row directly to the Excel file.

So would you say you are opposed to saving the file in a XML or CSV format? The reason I ask is they are both compatible with Excel (excel can open them just fine) but there are many methods available to string them together and even write the files a line at a time - so much so that it might be more flexible than trying to save a .xls file

Jared
Oct 29 '08 #10
kenobewan
4,871 Expert 4TB
These actions are not mutually exclusive, you could set a timeout in code before the transaction and then throw an error if timeout occurs. Custom error handling is set up if the web.config, assuming this is asp.net.
Oct 29 '08 #11
Curtis Rutland
3,256 Expert 2GB
Please don't double post your questions. If you made a mistake and need to change your question, you can click the Edit button to edit your post, or you can post your corrections in a reply to your original thread. If you can't find your original thread, click the "My Subscriptions" link near the top of the page. If you feel that your question has been overlooked, post a reply to it to "bump" it back to the top of the forum. We ask that you do this only once every 24 hours.

So there is no reason to double post. It makes it hard on the Experts and you to keep track of what help you've already been given.

Threads merged.

MODERATOR
Oct 29 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Not Me | last post by:
Hi, I'm trying to export from a gridview control, to an excel file using code intended for a datagrid control (it's all over the web, can post if requested) I get the error. Control...
6
by: Paul Zanbaka | last post by:
I have this code below it works fine when exporting to excel. However 2 things: 1-It does prompt me to save to file to excel (just displays excel in browser) 2-It aonly works if...
2
by: wubin_98 | last post by:
Hi, I want to export a gridview data and a image from image control to export to an Excel document. When I executed following code, GridView data was exported to Excel properly. But no image...
0
by: Peter | last post by:
I experienced a bug, "Control GridView1 of type GridView myst be placed inside a form tag with runat=server". But I did so. I do not why, please advise. my code as below. Thanks. Peter <%@...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
1
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The...
0
by: Mike | last post by:
On my page I'm using an updatepanel, updateProgress, and a ModalProgress, everything works great But when I try to export my GridView to excel I'm getting the following error message: ...
3
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.