Visual Basic: RDO Data Control
Move Methods Example
This example illustrates use of the rdAsyncEnable option in conjunction with the MoveLast method. The Phones table is simply a table with over 15,000 rows which takes some time to process. While this is not a recommended technique, it provides a way to illustrate a query that takes a significant length of time to run and fully populate as is done when you execute the MoveLast method. The application uses a status bar to indicate the degree of completion of the operations.
Option Explicit
Dim rdoCn As New rdoConnection
Dim rdoRs As rdoResultset
Dim SQL As String
Dim TimeExpected As Single
Dim Ts As Single, Tn As Single
Private Sub Command1_Click()
TimeExpected = 5 ' We expect this to take about 5 seconds
SQL = "Select Email, Name From Phones"
Set rdoRs = rdoCn.OpenResultset(Name:=SQL, _
Type:=rdOpenStatic, _
LockType:=rdConcurReadOnly, _
Option:=rdAsyncEnable)
ShowProgress "Query"
'
' Query Has completed... now move to the last row
'
rdoRs.MoveLast rdAsyncEnable
' We expect this to take about 15 seconds
TimeExpected = 15
ShowProgress "MoveLast"
rdoCn.Close
End Sub
Sub ShowProgress(Operation As String)
Ts = Timer
' time to execute query
ProgressBar1.Max = TimeExpected
While rdoRs.StillExecuting
Tn = Int(Timer - Ts)
If Tn < TimeExpected Then
ProgressBar1 = Tn
Else
ProgressBar1.Max = ProgressBar1.Max + 10
TimeExpected = ProgressBar1.Max
End If
DoEvents
Wend
Status = Operation & "Done. Duration:" _
& Int(Timer - Ts)
End Sub
Private Sub Form_Load()
With rdoCn
.Connect = "UID=;PWD=;Database=WorkDB;" _
& "Server=BETAV486;Driver={SQL Server}" _
& "DSN='';"
.LoginTimeout = 5
.EstablishConnection rdDriverNoPrompt, True
End With
Exit Sub
End Sub