0

I am using the following scenario for bulk insertion.

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

Throughout my project we frequently used these technique for bulk insertion. is there any similar way for bulk update? I had referred these links but they not match with my scenario

Community
  • 1
  • 1

1 Answers1

0

The answer is there in the reference link itself. go through that again care fully, or try this:

  queryBuilder.Append("ON DUPLICATE KEY UPDATE col2 = VALUES(col2)")

hence your whole code will be like the following:

    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