使用SqlBulkCopy进行批量数据插入
2024-08-30 20:43:33
Dim dt As DataTable = New DataTable()
dt.Columns.Add("DtCostProductRuleGUID", GetType(Guid))
dt.Columns.Add("RecollectGUID", GetType(Guid))
dt.Columns.Add("ProjCode", GetType(String))
dt.Columns.Add("ProductGUID", GetType(Guid))
dt.Columns.Add("CostCode", GetType(String))
dt.Columns.Add("CostShortName", GetType(String))
dt.Columns.Add("ParentCode", GetType(String))
dt.Columns.Add("CostLevel", GetType(Integer))
dt.Columns.Add("IfEndCost", GetType(Integer))
dt.Columns.Add("DtCost", GetType(Decimal))
dt.Columns.Add("IsAttend", GetType(Integer))
Dim row As DataRow
Using scope As ConnectionScope = New ConnectionScope
For Each xmlNode In xmlNodeList
strCostCode = xmlNode.Attributes("CostCode").Value
strCostShortName = xmlNode.Attributes("CostShortName").Value
strParetnCode = xmlNode.Attributes("ParentCode").Value
iCostLevel = CInt(xmlNode.Attributes("CostLevel").Value)
iIfEndCost = CInt(xmlNode.Attributes("IfEndCost").Value)
decDtCost = CDec(xmlNode.Attributes("DtCost").Value)
For i = To iProductCount -
row = dt.NewRow()
row("DtCostProductRuleGUID") = Guid.NewGuid()
row("CostCode") = strCostCode
row("CostLevel") = iCostLevel
row("CostShortName") = strCostShortName
row("DtCost") = decDtCost
row("IfEndCost") = iIfEndCost
row("IsAttend") = xmlNode.Attributes(dtProduct.Rows(i).Item("Product")).Value.ToString()
row("ParentCode") = strParetnCode
row("ProductGUID") = dtProduct.Rows(i).Item("ProductGUID").ToString()
row("ProjCode") = sProjCode
row("RecollectGUID") = sRecollectGUID
dt.Rows.Add(row)
Next
Next
'保存金蝶业态
xmlNode = xmlDOM.SelectSingleNode("/data/jdRow")
For i = To iProductCount -
strSQL = "update cb_JdProductRule set JdProductName='" & xmlNode.Attributes(dtProduct.Rows(i).Item("Product")).Value.ToString() & _
"' where RecollectGUID=@RecollectGUID and ProductGUID='" & dtProduct.Rows(i).Item("ProductGUID").ToString() & "';" sbStr.Append(strSQL)
Next
CPQuery.From(sbStr.ToString(), param).ExecuteNonQuery() Dim bulkCopy As SqlBulkCopy = scope.CreateSqlBulkCopy(SqlBulkCopyOptions.FireTriggers)
bulkCopy.DestinationTableName = "cb_DtCostProductRule"
bulkCopy.WriteToServer(dt)
End Using
最新文章
- 获取app安装信息私有api
- android json解析详细介绍之gson
- LintCode 整数排序
- CODEVS1001 舒适的路线 (并查集)
- read the python code and predict the results --- from <;Learn Python The Hard Way>;
- Js获取当前日期时间及其它操作(转)
- kendo ui template的用法
- linux命令学习02-通过tomcat学习ps和netstat
- 全排列 ( next_permutation)
- LeetCode 243. Shortest Word Distance (最短单词距离)$
- python模拟shell执行脚本
- Java经典编程题50道之三十
- Linux+Shell常用命令总结
- C#异常:未将对象引用设置到对象的实例。
- Docker学习笔记之搭建 Java Web 项目运行环境
- stenciljs 学习八 组件测试
- 异步FIFO空满设计延迟问题
- ASP.NET MVC3默认提供了11种ActionResult的实现
- 图形管线之旅 Part2
- 解压zip,解决中文乱码