oracle 将 gridview 绑定到具有超过 400000 条记录的数据表时出现 System.OutOfMemoryException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3809968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.OutOfMemoryException when binding a gridview to a datatable having more then 400000 records
提问by Ritesh Ranjan
Dear, I am facing system.outofmemmory exception when binding a gridview with a datatable having more then 400000 records please find the below sample code for the same
亲爱的,我在将 gridview 与具有超过 400000 条记录的数据表绑定时遇到 system.outofmemmory 异常,请找到以下相同的示例代码
GridView gv = new GridView();
this.EnableViewState = false;
gv.DataSource = (DataTable)dt;
gv.DataBind();
Kindly help me to overcome in this situation is there any limitation of gridview for databind?
请帮助我克服这种情况,gridview 对 databind 有任何限制吗?
回答by Michael Petrotta
A datagrid is limited by available system memory, and you're likely running into that. Assuming a process address space of, say, 1.5GB, that's about 4KB per datagrid row, if you had nothingelse consuming memory in your process. 4KB is not unreasonable, assuming a dozen or so wide columns.
数据网格受可用系统内存的限制,您可能会遇到这种情况。假设进程地址空间为 1.5GB,那么每个数据网格行大约有 4KB,如果您的进程中没有其他消耗内存的东西。假设有十几个宽的列,4KB 也不是不合理。
You're trying to display too many rows at once. I have to assume it's a pretty bad user experience too, trying to navigate through that many rows. Look at pagingthem instead.
您试图一次显示太多行。我不得不假设这也是一个非常糟糕的用户体验,试图浏览那么多行。看看对它们进行分页。
回答by Bart Verkoeijen
As suggested already, paging is the common way to handle large amounts of records in web apps.
如前所述,分页是处理 Web 应用程序中大量记录的常用方法。
But if it is the requirement to show all records in the output (e.g. for reporting purposes) then there is a way to do it.
但是如果需要在输出中显示所有记录(例如用于报告目的),那么有一种方法可以做到。
Instead of keeping the resultset in memory on the server, you can also stream the data to the client. This can be achieved by using a DataReader instead of a DataSet and disabling all caching mechanisms.
您还可以将数据流式传输到客户端,而不是将结果集保存在服务器的内存中。这可以通过使用 DataReader 而不是 DataSet 并禁用所有缓存机制来实现。
A simple way to do this is using a SqlDataSource control for instance. Hook up the data source to a grid view as usual. Then change the DataSourceMode on the data source from DataSet to DataReader. Disable the page output cache, and you are ready to go.
例如,一种简单的方法是使用 SqlDataSource 控件。像往常一样将数据源连接到网格视图。然后将数据源上的 DataSourceMode 从 DataSet 更改为 DataReader。禁用页面输出缓存,您就可以开始了。
回答by Merrimack
That's a lot of rows! You need to apply paging for that amount of rows to be manageable. If the reason you are displaying that many rows is that you need to find certain data you should implement a search function as well.
这是很多行!您需要为可管理的行数应用分页。如果您显示这么多行的原因是您需要查找某些数据,您还应该实现搜索功能。
Here's a guide from MS on how to enable paging: http://msdn.microsoft.com/en-us/library/aa479347.aspx
这是 MS 关于如何启用分页的指南:http: //msdn.microsoft.com/en-us/library/aa479347.aspx