SqlBulkCopy implements import of mass data and sqlbulkcopy
// Regenerate the auto-increment column: SqlBulkCopy bc = new SqlBulkCopy (conn) // retain the original value of the auto-increment column: SqlBulkCopy bc = new SqlBulkCopy (conn, SqlBulkCopyOptions. keepIdentity) using (SqlBulkCopy sbc = new SqlBulkCopy (conn, SqlBulkCopyOptions. keepIdentity) {sbc. destinationTableName = tableName; foreach (string col in colList) {sbc. columnMappings. add (col, col);} sbc. bulkCopyTimeout = 0; sbc. writeToServer (dt );}
SqlBulkCopy adopts the BCP Protocol of SQL Server for Batch Data Replication. In combination with transactions, about 800 entries per batch is the balance point in our case, the performance is improved by more than 100 times than insert one by one, and the performance of the case with transaction batch insert is also improved by more than 7 times.
Personal Website: http://www.51pansou.com
. Net video download:. net video tutorial
. Net source code download:. net source code