标签:
简介:NPOI批量导入大量数据
使用SqlBulkCopy 可以将datatable里面的大量数据批量复制到数据库中,而不用担心性能问题,比系统中的传统做法(每20行数据执行一遍mydb.execute强多了)
SqlBulkCopyColumnMapping(源列名,目标列名)
附代码如下:
Try Using sqlblk As New SqlBulkCopy(MyDB.GetSqlConnectionString()) sqlblk.BatchSize = DtInput.Rows.Count sqlblk.BulkCopyTimeout = 100 sqlblk.DestinationTableName = "cg_ProductBillDtl" sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductBillGUID", "ProductBillGUID")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductBillDtlGUID", "ProductBillDtlGUID")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductGUID", "ProductGUID")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductTypeCode", "ProductTypeCode")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductName", "ProductName")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductSpec", "ProductSpec")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductModel", "ProductModel")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("ProductUnit", "ProductUnit")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("Price", "Price")) sqlblk.ColumnMappings.Add(New SqlBulkCopyColumnMapping("Remark", "Remark")) sqlblk.WriteToServer(DtInput) End Using Catch ex As Exception MyDB.LogException(ex) End Try
标签:
原文地址:http://www.cnblogs.com/KingUp/p/5741210.html