Results 1 to 10 of 10

Thread: [RESOLVED] Progress Bar

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: Progress Bar

    Thanks i will try what you said

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: Progress Bar

    how do you trigger a progress bar when its style is set to marquee? thanks!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Progress Bar

    You don't have to. It just scrolls continuously.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    Re: Progress Bar

    Sorry for this another newbie question, how will i attached the entire click handler event to another event sir?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    129

    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
  •  



Click Here to Expand Forum to Full Width