Link to home
Start Free TrialLog in
Avatar of dreinmann
dreinmannFlag for United States of America

asked on

Progress Bar

How can I show a Progress Bar and attach it to a DataSet.Fill?  vb.net please
Me.Service_Time_by_Day_ReportTableAdapter.Fill(Me.ServTimeDataSet1.Service_Time_by_Day_Report)
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

no events are trigerred while the dataset is filling so you can't have a progress bar.
Are you using 2005?  If so, you can break the Fill down to steps by using the overloaded Fill method that takes start index plus number of records to fill.

Bob
Avatar of dreinmann

ASKER

Yes, using VS 2005.  Can you show an example of what you're saying?
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Really nice comments from Bob...added this one to my favorites _-;)

vbturbo
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tried:  Service_Time_by_Day_ReportTableAdapter.Fill(ServTimeDataSet1, 9, 15, "Service_Time_by_Day_Report")   ....this is not working.

Says for the DataSet - 'Value of Type 'System.Data.DataSet' cannot be converted to 'WindowsApplication1.ServTimeDataSet.Service_Time_by_Day_ReportDataTable'.  

Says for the rest - Too many arguments.

Can I use dbDataAdapter for database that reside within the program.  (not on a sql server)?
I created an OleDbDataAdapter, did a BindingSource and wrote this code:  (but, still not getting lines 10-15 on DataTableReader) ...what's wrong?
ServTimeDataSet1.Tables.Add("Service_Time_by_Day_Report")
        AddHandler ServTimeDataSet1.Tables(0).RowChanged, AddressOf Progress
        servAdapter.Fill(ServTimeDataSet1, 9, 15, "Service_Time_by_Day_Report")
Me.Cursor = Cursors.AppStarting
        lblServTimeTag.Text = "Processing Service Times..."
        lblServTimeTag.Refresh()
        Dim sw1 As StreamWriter
        sw1 = New StreamWriter("G:\Operations\Transportation\07 Service Time Import\Service Time by Day Report.txt")
        Dim dt As New DataTable
        dt = Me.ServTimeDataSet1.Service_Time_by_Day_Report
        Dim rv As DataTableReader
        rv = dt.CreateDataReader
        tsbProgress.Style = ProgressBarStyle.Continuous
        tsbProgress.Value = 0
        tsbProgress.Maximum = CInt(Me.ServTimeDataSet1.Service_Time_by_Day_Report.Count())
        tsbProgress.PerformStep()
        Using reader As DataTableReader = dt.CreateDataReader()
            Threading.Thread.Sleep(2000)
            Do While reader.Read()
                tsbProgress.PerformStep()
                sw1.WriteLine(reader(0).ToString() & " " _
                & reader(1).ToString() & " " & reader(2).ToString() & " " _
                & reader(3).ToString())
            Loop
            Threading.Thread.Sleep(1000)
            Application.DoEvents()
        End Using
        sw1.Close()
Private Sub Progress(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs)
        tsbProgress.Value += 1
    End Sub
Avatar of iboutchkine
iboutchkine

Is it a Service or standalone program?
StandAlone - the Access database is imported into the VS project and a couple tables from it are linked to outside sources.
I think I'm close, but maybe need to do some changes in the DataTableReader?  That's what worked when I was using the 'TableAdapter', but now that I'm trying to go through dbDataAdapter do I have to use something different?
Also, I wasn't getting exactly lines 9-15.  Whatever I set the upper to, I would get from 0 to the upper.  In this case 0 to 15 records...I changed it to 12-20 and got records 0-20.  Know why?
The first number is the starting record, and the second number is the max record.  If you set the starting record at 12, and the max length at 20, you should have gotten 12-32.

Bob
Final code...thanks for all the help.  Ended up having to change the 'dt = Me.ServTimeDataSet1.Service_Time_by_Day_Report' to 'dt = ServTimeDataSet1.Tables("Service_Time_by_Day_Report")'


lblServTimeTag.Text = "Loading Service Times, could take up to 1 minute..."
        lblServTimeTag.Refresh()
        tsbProgress.Maximum = 2000
        Me.Cursor = Cursors.WaitCursor
        ServTimeDataSet1.Tables.Add("Service_Time_by_Day_Report")
        AddHandler ServTimeDataSet1.Tables("Service_Time_by_Day_Report").RowChanged, AddressOf Progress
        servAdapter.Fill(ServTimeDataSet1, 9, 15, "Service_Time_by_Day_Report")

        'TODO: This line of code loads data into the 'ServTimeDataSet1.Service_Time_by_Day_Report' table. You can move, or remove it, as needed.
        'Me.Service_Time_by_Day_ReportTableAdapter.Fill(Me.ServTimeDataSet1.Service_Time_by_Day_Report)
        Me.Cursor = Cursors.AppStarting
        lblServTimeTag.Text = "Processing Service Times..."
        lblServTimeTag.Refresh()
        Dim sw1 As StreamWriter
        sw1 = New StreamWriter("G:\Operations\Transportation\07 Service Time Import\Service Time by Day Report.txt")
        Dim dt As New DataTable
        dt = ServTimeDataSet1.Tables("Service_Time_by_Day_Report")
        Dim rv As DataTableReader
        rv = dt.CreateDataReader
        tsbProgress.Style = ProgressBarStyle.Continuous
        tsbProgress.Value = 0
        tsbProgress.Maximum = CInt(Me.ServTimeDataSet1.Service_Time_by_Day_Report.Count())
        tsbProgress.PerformStep()
        Using reader As DataTableReader = dt.CreateDataReader()
            Threading.Thread.Sleep(2000)
            Do While reader.Read()
                tsbProgress.PerformStep()
                sw1.WriteLine(reader(0).ToString() & " " _
                & reader(1).ToString() & " " & reader(2).ToString() & " " _
                & reader(3).ToString())
            Loop
            Threading.Thread.Sleep(1000)
            Application.DoEvents()
        End Using
        sw1.Close()