Hi, i want to implement a progress bar using another form while i am uploading a file in the database. How can i do it? i will appreciate your help. :)
Printable View
Hi, i want to implement a progress bar using another form while i am uploading a file in the database. How can i do it? i will appreciate your help. :)
You can't really display actual progress because ADO.NET won't give you any feedback on the progress of an update. What you can do is display a marquee progress bar, just to indicate that something is happening. Just create a form and add a ProgressBar and set its Style property to Marquee. You can then add a BackgroundWorker and do your data access in its DoWork event handler, then close the form in the RunWorkerCompleted event handler. Follow the BackgroundWorker link in my signature for an example of how to use it if you don't already know.
Thanks i will try what you said :)
how do you trigger a progress bar when its style is set to marquee? thanks!
You don't have to. It just scrolls continuously.
i still have this clouded understanding on backgroundworker, this is how i manage to do this. How will i include my processing inside the do work handler? thank you for your help.
Code:Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
pbUpload.Value = 0
btnClose.Enabled = False
bgwUpload.WorkerReportsProgress = True
bgwUpload.RunWorkerAsync()
Dim SourceTable As DataTable = GetDataTableFromFile("C:\ItemMasterFile.csv", ",", 21)
gcon.sqlconn.Open()
Using CopyDatabase As SqlBulkCopy = New SqlBulkCopy(gcon.sqlconn)
Dim sourceHeader() As String = getHeaderFromSource("C:\ItemMasterFile.csv", ",")
Dim destinationHeader() As String = getHeaderFromDestination()
Dim index As Integer = 0
CopyDatabase.DestinationTableName = "dbo.mTemporaryUpload"
For index = 0 To sourceHeader.Length - 1
Dim mapColumn As New SqlBulkCopyColumnMapping(sourceHeader(index), destinationHeader(index))
CopyDatabase.ColumnMappings.Add(mapColumn)
Next
Try
CopyDatabase.WriteToServer(SourceTable)
updateItemCodeTable()
updateItemBrandTable()
updateItemCategoryTable()
updateItemSizeTable()
updateColorTable()
updateItemMaster()
MsgBox("Uploading Successful!", MsgBoxStyle.Exclamation, "Upload")
Catch ex As Exception
MsgBox("Error in Uploading")
End Try
End Using
gcon.sqlconn.Close()
End Sub
Code:Private Sub bgwUpload_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwUpload.DoWork
End Sub
Private Sub bgwUpload_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgwUpload.ProgressChanged
pbUpload.Value = e.ProgressPercentage
End Sub
Private Sub bgwUpload_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgwUpload.RunWorkerCompleted
btnClose.Enabled = True
End Sub
What's the work you're doing at the moment? It's the contents of that Click event handler, right? So you just take that entire block and stick it in the DoWork event handler. Done.
Sorry for this another newbie question, how will i attached the entire click handler event to another event sir?
You won't attach the entire click handler to another event. You will take the work, i.e. the code in the Click event handler, and put it somewhere else, i.e. in the DoWork event handler of the BackgroundWorker.
Thank you for your patience.I was able to do it now.