I'm trying into upload to a database records in batches of 10 using SqlBulkCopy. Some of the data already exists in the destination table so, even if one record out of ten exists, the rest fail to get uploaded as well. Is there a way to upload the remaining 9 records?
Try
Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(conBSD)
bulkCopy.DestinationTableName = "dbo.cheques2"
' Write from the source to the destination.
bulkCopy.BulkCopyTimeout = 60
bulkCopy.WriteToServer(dtToUpload)
iSuccessInserted += 10
dtToUpload.Clear()
dtToUpload.Dispose()
MsgBox("Current " & iCurrent.ToString & " - " & " In table toUpload " )
End Using
'Duplicate key, access violation when trying to insert record with same recordID
Catch ex As SqlException When ex.ErrorCode = -2146232060
MsgBox(ex.Message & " " & ex.ErrorCode)
dtToUpload.Clear()
dtToUpload.Dispose()
Exit Try
Catch ex As Exception
MsgBox(ex.Message)
End Try