使用.net Datatable的最佳方法,包含大量数据 [英] best way to use .net Datatable with a huge data
问题描述
大家好,
我需要你的帮助,请非常紧急的问题,我需要用大量数据(约400 MB)填充.net数据表,当时加载数据我面临内存问题,内存不足异常,我发现内存需要1GB以上。
我搜索这个问题找一个人说到使用.Net数据表时它会生成这个.net数据表的3个副本。
我的问题是:
什么是使用带有大量数据的.net Datatable的最佳方法?
以避免内存问题?
提前谢谢
Hi All,
I need your help please in very urgent issue, I need to fill a .net datatable with a huge data( about 400 MB), when load data i face a memory problem , Out of memory exception , i found it take more than 1GB from memory.
I search about this problem and find somebody talk that when use .Net datatable it makes 3 copies of this .net datatable.
My Question is:
what is the best way to use .net Datatable with a huge data?
to avoid memory problems??
Thanks in advance
推荐答案
您的DataTable中有多少行?
How many rows in your DataTable?
如果你必须达到这个限制,你的应用程序就会遇到更严重的问题...
它是 System.Int32.MaxValue
,或2,147,483,647。但由于你不能在不产生OutOfMemory异常的情况下达到该限制,它受可用内存的限制。
If you have to hit that limit, you've got bigger issues with your application...
It's System.Int32.MaxValue
, or 2,147,483,647. But since you wont be able to reach that limit without generating an OutOfMemory Exception, it's limited by available memory.
要向DataTable添加行,必须先使用NewRow方法返回一个新的DataRow对象。 NewRow方法返回一个包含DataTable模式的行,因为它由表的DataColumnCollection定义。 DataTable可以存储的最大行数为16,777,216。有关详细信息,请参阅向DataTable添加数据。
To add rows to a DataTable, you must first use the NewRow method to return a new DataRow object. The NewRow method returns a row with the schema of the DataTable, as it is defined by the table's DataColumnCollection. The maximum number of rows that a DataTable can store is 16,777,216. For more information, see Adding Data to a DataTable.
最好的方法是拆分DataTable
如何拆分一个数据表到多个数据表? [ ^ ]
使用ADO.NET的最佳实践 [ ^ ]
本文为您提供了在Microsoft ADO.NET应用程序中实现和实现最佳性能,可伸缩性和功能的最佳解决方案;它还介绍了使用ADO.NET中可用对象时的最佳实践,并提供了可以帮助您优化ADO.NET应用程序设计的建议。
Best Practices for Using ADO.NET[^]
This article provides you with the best solutions for implementing and achieving optimal performance, scalability, and functionality in your Microsoft ADO.NET applications; it also covers best practices when using objects available in ADO.NET and offers suggestions that can help you optimize the design of your ADO.NET application.
由于数据量很大,在我看来,你应该将数据存储在例如数据库中,并在需要时只获取它的必要部分。例如,您可以使用:
- SQL Server Compact Edition [ ^ ]
- Microsoft SQL Server Express Edition [ ^ ]
Since the amount of data is quite big, in my opinion you should store the data for example in a database and fetch only a necessary portion of it whenever needed. For example you can use:
- SQL Server Compact Edition[^]
- Microsoft SQL Server Express Edition[^]
这篇关于使用.net Datatable的最佳方法,包含大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!