Hi! I tried running this backgroundworker of jm which is perfectly running.
vb Code:
  1. Public Class frmBackGroundWorker
  2.     Private Sub frmBackGroundWorker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         'Raise the DoWork event in a worker thread.    
  4.         Me.BackgroundWorker1.RunWorkerAsync()
  5.     End Sub
  6.  
  7.     'This method is executed in a worker thread.
  8.     Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  9.         Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
  10.         For i As Integer = 1 To 100
  11.             'Raise the ProgressChanged event in the UI thread.        
  12.             worker.ReportProgress(i, i & " iterations complete")
  13.             'Perform some time-consuming operation here.        
  14.             Threading.Thread.Sleep(250)
  15.         Next i
  16.     End Sub
  17.  
  18.     'This method is executed in the UI thread.
  19.     Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
  20.         Me.ProgressBar1.Value = e.ProgressPercentage
  21.         Me.Label1.Text = TryCast(e.UserState, String)
  22.     End Sub
  23.  
  24.     'This method is executed in the UI thread.
  25.     Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
  26.         Me.Label1.Text = "Operation complete"
  27.     End Sub
  28. End Class
the project i am working will access a database table that will take some time to load and I would like that while it is being fetch, users will see a progress of the loading process. How do i make backgroundworker use the data amount of data as value of the progressbar?

Right now, I click a button to fetch the records from a database table. Below is my code
Code:
   Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        SuspendLayout()
        cnn.ConnectionString = "Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True"

        If cnn.State = ConnectionState.Closed Then cnn.Open()


        cmdGrade = cnn.CreateCommand
        cmdGrade.CommandText = "SELECT DISTINCT * FROM tblEnrol WHERE SectionName = '" & cboSection.Text & "' AND SubjectName = '" & cboSubjectName.Text & "' AND YearLevel = '" & cboYearLevel.Text & "'"
        daGrade.MissingSchemaAction = MissingSchemaAction.AddWithKey
        dsGrade.Clear()
        'dsSection.Clear()
        'dsSubject.Clear()
        daGrade.SelectCommand = cmdGrade
        daGrade.Fill(dsGrade, "tblEnrol")
        cnn.Close()



        Dim si() As FarPoint.Win.Spread.SortInfo = New FarPoint.Win.Spread.SortInfo() {New FarPoint.Win.Spread.SortInfo(1, True), New FarPoint.Win.Spread.SortInfo(2, True)}

        ''HideSheets()

        'bind fpspread1 to datasource
        '1st Grading
        FpSpread1.Sheets(0).DataSource = dsGrade
        FpSpread1.Sheets(0).DataMember = "tblEnrol"

        'Create CellType and specify number decimal for 1st grading sheet
        With FpSpread1.Sheets(0)
            .DataAutoCellTypes = False
            Dim num As New FarPoint.Win.Spread.CellType.NumberCellType
            num.DecimalPlaces = 0
            .Columns(12, 81).CellType = num 'column 12 to 81
            .Columns(84, 85).CellType = num
            .Columns(88, 89).CellType = num
            .Columns(92, 93).CellType = num
            .Columns(96, 97).CellType = num
            .Columns(100, 101).CellType = num
            .Columns(104, 105).CellType = num
            .Columns(109).CellType = num

            'sort multi-column
            .SortRows(0, FpSpread1.Sheets(0).RowCount, si)

        End With
        FormatSpread()

        'bind FpSpread1.Sheets(1) to datasource
        '2nd Grading
        FpSpread1.Sheets(1).DataSource = dsGrade
        FpSpread1.Sheets(1).DataMember = "tblEnrol"

        'Create CellType and specify number decimal for 1st grading sheet
        With FpSpread1.Sheets(1)
            .DataAutoCellTypes = False
            Dim num As New FarPoint.Win.Spread.CellType.NumberCellType
            num.DecimalPlaces = 0

            'for 2nd grading cell type
            .Columns(135, 204).CellType = num 'Assignment to Total Score (A)
            .Columns(207, 208).CellType = num 'Total Quiz to Total Score (Q)
            .Columns(211, 212).CellType = num 'Total Rec to Total Score (R)
            .Columns(215, 216).CellType = num 'Total Proj to Total Score (P)
            .Columns(219, 220).CellType = num 'Total Speech to Total Score (SP)
            .Columns(223, 224).CellType = num 'Total Reading to Total Score (RDG)
            .Columns(227, 228).CellType = num 'Total Exam to Total Score (E)
            .Columns(232).CellType = num 'Average
        End With
        FormatSpread1()

        ResumeLayout()

    End Sub