Bulk copy in vb.net

Public Shared Function InsertQueries(ByVal DestinationTable As String, ByVal dt As DataTable, ByVal keepIdentity As Boolean, ByVal ds As DataSet) As Int64 Dim bulkCopy As SqlBulkCopy Dim strConnection As String = ConfigurationManager.ConnectionStrings("TargetConnection").ConnectionString bulkCopy = New SqlBulkCopy(strConnection, SqlBulkCopyOptions.KeepNulls) Dim destcolumn As New ArrayList Dim srcColumn As New ArrayList Dim i As Integer

Dt contains the list columns for source table

If ds.Tables(0).Rows.Count <> dt.Columns.Count Then ds.Tables(0).Rows.RemoveAt(0) End If Dim mappedColumns As ArrayList = New ArrayList() For i = 0 To dt.Columns.Count - 1 Dim mapName As New SqlBulkCopyColumnMapping(dt.Columns(i).ColumnName.ToString(), ds.Tables(0).Rows(i).Item(0).ToString()) mappedColumns.Add(mapName) Next For i = 0 To mappedColumns.Count - 1 bulkCopy.ColumnMappings.Add(mappedColumns(i)) Next bulkCopy.DestinationTableName = DestinationTable bulkCopy.WriteToServer(dt) bulkCopy.Close() End Function