如何将5 lac记录插入sql server [英] How to insert 5 lac record into sql server
本文介绍了如何将5 lac记录插入sql server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在开发Windows服务。我正在开发一个Windows服务,它将平面文件中的记录提取到数据表中。现在这个数据表记录了大约5行要插入sql server。请告诉我执行此任务的有效方法。
Hi There,
I am working on windows service. I am developing an windows service which fetch record from flat file into datatable. Now this datatable records around 5 lacs rows want to insert in sql server. Please tell me the efficient way to do this task.
推荐答案
使用SqlBulkCopy [ ^ ] class。
Use the SqlBulkCopy[^] class.
用于将大数据插入sql server更好地使用sql批量复制,如下所示
Hi,
For inserting large data into sql server better to use sql bulk copy like as follows
DataTable mydatatable= mydata;
// Get a reference to a single row in the table.
DataRow[] rowArrayMydata = mydatatable.Select();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con, SqlBulkCopyOptions.KeepIdentity, transaction))
{
bulkCopy.DestinationTableName = "MyDestinationTable";
// Write the array of rows to the destination.
bulkCopy.WriteToServer(rowArrayMydata );
}
参考这些:
使用SqlBulkCopy传输数据 [ ^ ]
SQL批量复制方法将大量数据插入sql数据库 [ ^ ]
Refer to these:
Transferring Data Using SqlBulkCopy[^]
SQL Bulk copy method to insert large amount of data to the sql database[^]
这篇关于如何将5 lac记录插入sql server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文