c#中批量记录的数据表内存不足错误 [英] Datatable Out of Memory Error for Bulk Records in c#
问题描述
hi
我使用winform 2008和c#以及mysql服务器。我在表中有1500000条记录。我希望导出每个65000到Excel导出
i m using winform 2008 with c# and mysql server. i have 1500000 records in table. i want export each 65000 to Excel Export
using (MySqlCommand cmmd = new MySqlCommand("select * from Z_Table", Ncon))
{
using (MySqlDataReader drr = cmmd.ExecuteReader())
{
NewTable.Load(drr);
}
}
dataGridView1.DataSource = null;
dataGridView1.DataSource = NewTable;
成功显示在网格中。
导出Excel
List<DataTable> tables = new List<DataTable>();
int count = 0;
DataTable copyTable = null;
foreach (DataRow dr in ExportTable.Rows)
{
if ((count++ % 65000) == 0)
{
copyTable = new DataTable();
copyTable = ExportTable.Clone();
tables.Add(copyTable);
}
copyTable.ImportRow(dr); // Out of memory Exception
}
仅针对批量记录的内存不足错误。我尝试了很多方法,但都失败了。我花了好几天但没有得到答案。
out of memory error only for bulk records. i tried many ways but all failed. i spent days but not get answer.
Plantform:x86
Plantform : x86
任何人都尽快告诉我解决方案
anyone tell me the solution as soon as possible
谢谢和问候,
推荐答案
嗨Brinda,
Hi Brinda,
我猜你在导出到excel时没有分页,请执行。
I guess you did not paginate when you exported to excel, please do it.
并尝试参考以下链接:
http:// stackoverflow。 com / questions / 9175741 / out-of-memory-exception-when-huge-data-from-db
希望它有所帮助!
最诚挚的问候,
Stanly
这篇关于c#中批量记录的数据表内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!