Use SQLBulkCopy Method To Transfer Data ...... This Is Use To Hundred Thousand Data In Several Seco
Use SQLBulkCopy Method To Transfer Data ...... This Is Use To Hundred Thousand Data In Several Seconds. With Progress Feature.
API Declarations
.SqlClient
Rate Use SQLBulkCopy Method To Transfer Data ...... This Is Use To Hundred Thousand Data In Several Seco
(1(1 Vote))
Private Rcount As Long = 0
Private Sub ButtonBulkCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBulkCopy.Click
Dim Scon As New SqlConnection("Data Source=MYPC;Initial Catalog=MyTest;Integrated Security=True")
Scon.Open()
Dim Scom As New SqlCommand("SELECT COUNT(*) FROM BulkData", Scon)
Rcount = Convert.ToInt32(Scom.ExecuteScalar())
LabelCounting.Text = "Starting Row Count :- " & Rcount
LabelCounting.Refresh()
With ProgressBarSQL
.Minimum = 0
.Maximum = Rcount
.Value = 0
End With
Scom.Cancel() : Scom.Dispose()
Scom = New SqlCommand("SELECT ItemNo,BulkItemName,BulkTime FROM BulkData ORDER BY ItemNo", Scon)
Dim Rdr As SqlDataReader = Scom.ExecuteReader()
Dim BulkCopy As New SqlBulkCopy("Data Source=MYPC;Initial Catalog=MyTest;Integrated Security=True")
BulkCopy.DestinationTableName = "BackupBulkData"
AddHandler BulkCopy.SqlRowsCopied, AddressOf OnSQLRowCopied
BulkCopy.NotifyAfter = 50
Try
BulkCopy.WriteToServer(Rdr)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Rdr.Close()
End Try
End Sub
Private Sub OnSQLRowCopied(ByVal sender As Object, ByVal e As SqlRowsCopiedEventArgs)
LabelCounting.Text = "Copied Data So Far :- " & e.RowsCopied
LabelCounting.Refresh()
ProgressBarSQL.Value = e.RowsCopied
End Sub
End Class
Use SQLBulkCopy Method To Transfer Data ...... This Is Use To Hundred Thousand Data In Several Seco Comments
No comments yet — be the first to post one!
Post a Comment