Question on an app I'm developing using VB.NET. I'm wanting to use a progress bar to show the progress of my
SqlBulkCopy procedure. I've looked up some ways and was wondering if using an
AddHandler in my
SqlBulkCopy procedure, using
SqlRowsCopied is a possible way to calculate the progress. And if so, how would I implement this, as I'm a bit new to progress bars in VB.NET. Let me know if there's a better way of going around this, all answers are very appreciated! THANKS! Just a small snippet of my
SqlBulkCopy being executed.
(FYI: Not showing anything I've attempted with the progress bar)
Progress bar is named
Dim copy As New SqlBulkCopy(con) For Each dc As DataColumn In dtDataCopy.Columns copy.ColumnMappings.Add(dc.ColumnName, dc.ColumnName) Next copy.DestinationTableName = TableName copy.BulkCopyTimeout = 360 copy.BatchSize = 1000 copy.WriteToServer(dtDataCopy) copy.Close()
As the documentation states, the
SqlRowsCopied event is dependent on the
NotifyAfter property, NOT the
BatchSize property. You would set the
Maximum of your
ProgressBar to the total number of rows and the
Step property to the same as the
NotifyAfter value. Each time the
SqlRowsCopied event is raised, you call
PerformStep on the
ProgressBar and it will increment by the number of rows that have been copied.
Alternatively, you can simply assign the
e.RowsCopied value to the
Value property of the
ProgressBar. There is a code example provided in the MSDN documentation for the event. It's to be hoped that you have consulted the documentation before posting this question.