Dim dtVender As New DataTable()
dtVender.Columns.Add(New DataColumn())
dtVender.Columns.Add(New DataColumn())
dtVender.Columns.Add(New DataColumn())
Dim vRow As DataRow = dtVender.NewRow()
vRow.Item(0) = dsID
vRow.Item(1) = vender_no
vRow.Item(2) = sku_id
dtVender.Rows.Add(vRow)
Datatable'ı doldurduktan sonra aşağıdaki metodu kullanarak datatable içerisindeki verileri "tbl_Vender" tablosuna aktarabilirsiniz.
SQLBulkCopyToTable(dtVender, "tbl_Vender")
Private Sub SQLBulkCopyToTable(ByRef sourceDT As DataTable, destinationTableName As String)
Try
Using cn As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString").ToString())
cn.Open()
If sourceDT.Rows.Count > 0 Then
Using copy As New SqlBulkCopy(cn)
copy.DestinationTableName = destinationTableName
copy.BulkCopyTimeout = 5000
copy.BatchSize = 5000
copy.WriteToServer(sourceDT)
End Using
End If
End Using
Catch ex As Exception
End Try
End Sub
No comments:
Post a Comment