OLEDB slow performance when inserting multiple records from C# into an Excel spreadsheet

给你一囗甜甜゛ 提交于 2019-12-24 07:29:09

问题


I am using an OLEDB connection (Microsoft.ACE.OLEDB.12) to read records from a C# data table and put the records into an excel spreadsheet.

I am looping round each record in my data table and building up OLEDBCommand.CommandText using an "Insert into table name values (" etc. I am having to format the values appropriately so that string/char/integer/decimal are inserted correctly. This all works fine and my spreadsheet is created, however when there are loads of records to insert (e.g. 500,000 plus), then the performance is really slow and it takes for ever. Is there a quicker way of doing this, rather than reading one record from my C# datatable at a time, making sure that the SQL statement has the correct syntax for the datatype and inserting it one at a time?

Any help appreciated

Thanks


回答1:


Make sure that you use prepared statements for inserts http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.prepare.aspx



来源:https://stackoverflow.com/questions/7213611/oledb-slow-performance-when-inserting-multiple-records-from-c-sharp-into-an-exce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!