Change the cursor position to the first, last, next, or previous row within the specified dynaset. These move methods move the cursor to the next (previous, and so on) valid row, skipping rows that have been deleted.
oradynaset.MoveFirst oradynaset.DbMoveFirst
oradynaset.MoveLast oradynaset.DbMoveLast
oradynaset.MovePrevious oradynaset.DbMovePrevious
oradynaset.MoveNext oradynaset.DbMoveNext
The data control buttons map (from left to right or from top to bottom) to the MoveFirst
, MovePrevious
, MoveNext
, and MoveLast
methods. The BOF
and EOF
properties are never true when using the data control buttons.
When the first or last record is current, record movement does not occur if you use the MoveFirst
or MoveLast
methods, respectively. You force the query to completion if you use the MoveLast
method on a dynaset.
If you use the MovePrevious
method and the first record is current, there is no current record and BOF
is true. Using the MovePrevious
method again causes an error, although BOF
remains True
. If you use the MoveNext
method and the last record is current, there is no current record and EOF
is true. Using the MoveNext
method again causes an error, although EOF
remains true. Note that when the dynaset is created with the ORADYN_NO_MOVEFIRST
option, BOF
and EOF
are true whether the dynaset is empty or not.
When you open a dynaset, BOF
is False
and the first record is current. If a dynaset is empty, BOF
and EOF
are both true, and there is no current record.
If an Edit
or AddNew
operation is pending and you use one of the Move
methods indirectly by way of the data control, then the Update
method is invoked automatically, although, it can be stopped during the Validate
event.
If an Edit
or AddNew
operation is pending and you use one of the Move
methods directly without the data control, pending Edit
or AddNew
operations cause existing changes to be lost, although no error occurs.
Data is fetched from the database, as necessary, so performing a MoveFirst
operation followed by a MoveNext
operation incrementally builds the mirrored (cached) local set without requiring read-ahead of additional data. However, executing a MoveLast
operation requires that the entire query be evaluated and stored locally.
When a dynaset is attached to a data control, these methods first notify the Validate
event of the data control that record motion is about to occur. The Validate
handler can deny the request for motion, in which case the request is ignored. If the record pointer is successfully moved, then all custom controls attached to the data control are notified automatically of the new record position.
This example demonstrates record movement within a dynaset using the MoveFirst
, MoveNext
, MoveLast
, MovePrevious
methods. Copy and paste this code into the definition section of a form. Then, press F5.
Sub Form_Load () 'Declare variables Dim OraSession As OraSession Dim OraDatabase As OraDatabase Dim OraDynaset As OraDynaset 'Create the OraSession Object. Set OraSession = CreateObject("OracleInProcServer.XOraSession") 'Create the OraDatabase Object by opening a connection to Oracle. Set OraDatabase = OraSession.OpenDatabase("ExampleDb", "scott/tiger", 0&) 'Create the OraDynaset Object. Set OraDynaset = OraDatabase.CreateDynaset("select empno, ename from emp", 0&) MsgBox "Employee #" & OraDynaset.Fields("empno").value & ", " & _ OraDynaset.Fields("ename").value 'Move to the next record and display it. OraDynaset.MoveNext MsgBox "Employee #" & OraDynaset.Fields("empno").value & ", " & _ OraDynaset.Fields("ename").value 'Move to the last record and display it. OraDynaset.MoveLast MsgBox "Employee #" & OraDynaset.Fields("empno").value & ", " & _ OraDynaset.Fields("ename").value 'Move to the previous record and display it. OraDynaset.MovePrevious MsgBox "Employee #" & OraDynaset.Fields("empno").value & ", " & _ OraDynaset.Fields("ename").value End Sub