Skip to content

Instantly share code, notes, and snippets.

@underwhelmed
Created December 16, 2010 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underwhelmed/743492 to your computer and use it in GitHub Desktop.
Save underwhelmed/743492 to your computer and use it in GitHub Desktop.
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports SD.LLBLGen.Pro.ORMSupportClasses
Public Interface ISqlBulkCopyWrapper
Sub WriteToServer(ByVal destTableName As String, ByVal table As DataTable, ByVal mappings As IEnumerable(Of SqlBulkCopyColumnMapping), ByRef tran As ITransaction)
End Interface
Public Class SqlBulkCopyWrapper
Implements ISqlBulkCopyWrapper
Public Sub WriteToServer(ByVal destTableName As String, ByVal table As DataTable, ByVal mappings As IEnumerable(Of SqlBulkCopyColumnMapping), ByRef tran As ITransaction) Implements ISqlBulkCopyWrapper.WriteToServer
Dim copy As New SqlBulkCopy(CType(tran.ConnectionToUse, SqlConnection), _
SqlBulkCopyOptions.Default, _
CType(tran.PhysicalTransaction, SqlTransaction))
If Not mappings Is Nothing AndAlso mappings.Count > 1 Then
For Each map As SqlBulkCopyColumnMapping In mappings
copy.ColumnMappings.Add(map)
Next
End If
copy.DestinationTableName = destTableName
copy.WriteToServer(table)
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment