我正在使用以下方案进行批量插入。
Dim queryBuilder As New StringBuilder
queryBuilder.Append("Insert into myTable(col1,col2)values")
Dim loopFlag As Boolean = False
For i As Integer = 0 To 150
queryBuilder.Append("(" & i & ",'" & i & "th Value'),")
Next
If loopFlag Then
' call method to execute the query'
ExecuteQuery(RemoveTrailingComma(queryBuilder.ToString()))
End If
在我的整个项目中,我们经常使用这些技术进行批量插入。是否有任何类似的批量更新方式?我已经引用了这些链接,但它们与我的方案不匹配
答案 0 :(得分:0)
答案就在参考链接本身。再次完全关注,或试试这个:
queryBuilder.Append("ON DUPLICATE KEY UPDATE col2 = VALUES(col2)")
因此您的整个代码将如下所示:
Dim queryBuilder As New StringBuilder
queryBuilder.Append("Insert into myTable(col1,col2)values")
Dim loopFlag As Boolean = False
For i As Integer = 0 To 150
queryBuilder.Append("(" & i & ",'" & i & "th Value'),")
Next
Dim mySql As String = RemoveTrailingComma(queryBuilder.ToString()) & "ON DUPLICATE KEY UPDATE col2 = VALUES(col2)"
If loopFlag Then
ExecuteQuery(mySql)
End If