|
-
Nov 11th, 2008, 02:37 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Progress Bar
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.
-
Nov 11th, 2008, 03:46 AM
#2
Re: Progress Bar
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.
-
Nov 11th, 2008, 03:55 AM
#3
Thread Starter
Addicted Member
Re: Progress Bar
Thanks i will try what you said
-
Nov 11th, 2008, 05:05 AM
#4
Thread Starter
Addicted Member
Re: Progress Bar
how do you trigger a progress bar when its style is set to marquee? thanks!
-
Nov 11th, 2008, 05:19 AM
#5
Re: Progress Bar
You don't have to. It just scrolls continuously.
-
Nov 11th, 2008, 05:24 AM
#6
Thread Starter
Addicted Member
Re: Progress Bar
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
-
Nov 11th, 2008, 07:40 AM
#7
Re: Progress Bar
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.
-
Nov 11th, 2008, 08:41 PM
#8
Thread Starter
Addicted Member
Re: Progress Bar
Sorry for this another newbie question, how will i attached the entire click handler event to another event sir?
-
Nov 11th, 2008, 08:53 PM
#9
Re: Progress Bar
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.
-
Nov 11th, 2008, 10:04 PM
#10
Thread Starter
Addicted Member
Re: Progress Bar
Thank you for your patience.I was able to do it now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|