Results 1 to 7 of 7

Thread: **RESOLVED** Establish Progressbar w/ ADO Connection???

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679

    **RESOLVED** Establish Progressbar w/ ADO Connection???

    I have been searching this forum as well as the web to locate how I can accomplish this task...

    I have a form that connects to a database table, and since the table has many records and several users access it, I have found that it takes between 15-30 seconds to load (it should also be noted that there are several agregate functions involved within the Form Load)

    I would like to establish a progressbar that will show the users how long the connection is taking....

    I am interested in any other suggestions, but at this point I am lost...

    Thank you.
    Last edited by Salvatore; Jun 7th, 2004 at 07:09 AM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I have never tried this but it seems like it may work.

    Declare your recordset using Withevents so you can handle events
    Open/execute the query asynchronously.
    Use the FetchProgress event to update your progress bar.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    That sounds interesting....

    How do I go about declaring my recordsets using WithEvents???

    Also will the Windows Progressbar that comes with the VB6 work with Asynchronously query...somewhere I read something about the Progress bar not able to do that...

    But I am up for anything...I just am not too familiar with the process you suggesssted...if you have time, I would love to learn it..

    Thank you..

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    The progress bar has absolutly NOTHING to do with sync/async. What has to do with it is the ADO things and it's with it that you have to worry about because it might freeze your whole app
    \m/\m/

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    This code works for me somewhat. There is no property or information from ADO that indicates how many records will be returned from the database. I just set the ProgressBar.Max value to an "expected value" (ie I know my table contains 94000+ records, so I set it to 100,000). You could always run an Select Count(*) query beforehand.

    Since the querie(s) run asynchronously, your users can begin to use your application almost immediately.

    VB Code:
    1. Option Explicit
    2.  
    3. Private WithEvents oRS As ADODB.Recordset
    4.  
    5. Private Sub Form_Load()
    6.     Dim oConn As ADODB.Connection
    7.    
    8.     Set oConn = New ADODB.Connection
    9.     oConn.Open "provider=sqloledb;data source=servername;initial catalog=dbname;integrated security=sspi"
    10.    
    11.     Set oRS = New ADODB.Recordset
    12.     With oRS
    13.         .CursorLocation = adUseClient
    14.         .LockType = adLockReadOnly
    15.         .CursorType = adOpenStatic
    16.  
    17.         .Properties("Initial Fetch Size").Value = 10
    18.  
    19.          'the FetchProgress event will fire after every 500 records
    20.         .Properties("Background Fetch Size").Value = 500
    21.     End With
    22.    
    23.     oRS.Open "Select * From Tablename", oConn, , , adAsyncFetch Or adCmdText
    24.     Set oRS.ActiveConnection = Nothing
    25.  
    26.     'Display data from the first record.
    27.     Text1.Text = oRS.Fields(1).Value
    28.  
    29.  
    30.     oConn.Close
    31.     Set oConn = Nothing
    32. End Sub
    33.  
    34. Private Sub oRS_FetchComplete(ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    35.     ProgressBar1.Max = pRecordset.RecordCount
    36.     ProgressBar1.Value = ProgressBar1.Max
    37. End Sub
    38.  
    39. Private Sub oRS_FetchProgress(ByVal Progress As Long, ByVal MaxProgress As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
    40.     If MaxProgress > ProgressBar1.Max Then
    41.         ProgressBar1.Max = MaxProgress
    42.     End If
    43.     If Progress < ProgressBar1.Max Then
    44.         ProgressBar1.Value = Progress
    45.     Else
    46.         ProgressBar1.Value = ProgressBar1.Max
    47.     End If
    48. End Sub

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679
    Thanx brucevde, I will give it a shot!

    I appreciate your cooperation and welcome the opportunity to learn!!

    Thank you again

  7. #7
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    Re: **RESOLVED** Establish Progressbar w/ ADO Connection???

    I tried the code.

    The problem is that only the last FetchProgress event fires. For example if the recordset has 10,000 records and I set an update interval of 100 records, only the event showing record 9,900 fires.

    It seems that the recordset behaves synchronously instead of anynchronously.

    I use MDAC 2.8 and I set adAsynchFetch on the recordset.Open options

    --hyperspaced

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