MoveFirst、MoveLast、MoveNext 和 MovePrevious 方法 (ADO) MoveFirst, MoveLast, MoveNext, and MovePrevious Methods (ADO)

移动到指定 记录集 对象中的第一条、最后一条、下一条记录或上一条记录,并使该记录成为当前记录。Moves to the first, last, next, or previous record in a specified Recordset object and makes that record the current record.

语法Syntax

  
recordset.{MoveFirst | MoveLast | MoveNext | MovePrevious}  

备注Remarks

使用 MoveFirst 方法将当前记录位置移动到 记录集中 的第一条记录。Use the MoveFirst method to move the current record position to the first record in the Recordset.

使用 MoveLast 方法将当前记录位置移动到 记录集中 的最后一条记录。Use the MoveLast method to move the current record position to the last record in the Recordset. Recordset 对象必须支持书签或后向光标移动;否则,此方法调用将生成错误。The Recordset object must support bookmarks or backward cursor movement; otherwise, the method call will generate an error.

记录集 为空时,对 MoveFirstMoveLast 的调用 (BOFEOF 均为 True) 会生成错误。A call to either MoveFirst or MoveLast when the Recordset is empty (both BOF and EOF are True) generates an error.

使用 MoveNext 方法将当前记录位置向前移动一条记录 (向 记录集) 的底部移动。Use the MoveNext method to move the current record position one record forward (toward the bottom of the Recordset). 如果最后一条记录是当前记录并且您调用了 MoveNext 方法,则 ADO 会将当前记录设置为 记录集中 最后一条记录之后的位置 (EOFTrue) 。If the last record is the current record and you call the MoveNext method, ADO sets the current record to the position after the last record in the Recordset (EOF is True). EOF 属性已 为 True 时,尝试向前移动将生成错误。An attempt to move forward when the EOF property is already True generates an error.

在 ADO 2.5 和更高版本中,当对 记录集 进行筛选或排序并且当前记录的数据发生更改时,调用 MoveNext 方法会将游标从当前记录向前移动两条记录。In ADO 2.5 and later, when the Recordset has been filtered or sorted and the data of the current record is changed, calling the MoveNext method moves the cursor two records forward from the current record. 这是因为当更改当前记录时,下一条记录将成为新的当前记录。This is because when the current record is changed, the next record becomes the new current record. 更改后调用 MoveNext 会将游标从新的当前记录向前移动一条记录。Calling MoveNext after the change moves the cursor one record forward from the new current record. 这不同于 ADO 2.1 和更早版本中的行为。This is different from the behavior in ADO 2.1 and earlier. 在这些早期版本中,更改已排序或已筛选的 记录集中 的当前记录的数据不会更改当前记录的位置,并且 MoveNext 会在当前记录之后立即将光标移到下一条记录。In these earlier versions, changing the data of a current record in the sorted or filtered Recordset does not change the position of the current record, and MoveNext moves the cursor to the next record immediately after the current record.

使用 MovePrevious 方法将当前记录位置 (一条记录向下移动一条记录,直到记录 的顶部) 。Use the MovePrevious method to move the current record position one record backward (toward the top of the Recordset). Recordset 对象必须支持书签或后向光标移动;否则,此方法调用将生成错误。The Recordset object must support bookmarks or backward cursor movement; otherwise, the method call will generate an error. 如果第一条记录是当前记录并且您调用了 MovePrevious 方法,则 ADO 会将当前记录设置为 记录集中 第一条记录之前的位置 (BOFTrue) 。If the first record is the current record and you call the MovePrevious method, ADO sets the current record to the position before the first record in the Recordset (BOF is True). BOF 属性为 True 时,尝试向后移动将生成错误。An attempt to move backward when the BOF property is already True generates an error. 如果 记录集 对象不支持书签或后向光标移动,则 MovePrevious 方法将生成错误。If the Recordset object does not support either bookmarks or backward cursor movement, the MovePrevious method will generate an error.

如果 记录集 是只进的并且您希望同时支持向前滚动和向后滚动,则可以使用 CacheSize 属性创建一个记录缓存,该缓存将支持通过 Move 方法向后光标移动。If the Recordset is forward only and you want to support both forward and backward scrolling, you can use the CacheSize property to create a record cache that will support backward cursor movement through the Move method. 由于缓存的记录已加载到内存中,因此应避免缓存超过所需的记录。Because cached records are loaded into memory, you should avoid caching more records than is necessary. 可以在只进 Recordset 对象中调用 MoveFirst 方法;这样做可能会导致提供程序重新执行生成 Recordset 对象的命令。You can call the MoveFirst method in a forward-only Recordset object; doing so may cause the provider to re-execute the command that generated the Recordset object.

应用于Applies To

记录集对象 (ADO)Recordset Object (ADO)

另请参阅See Also

MoveFirst、MoveLast、MoveNext 和 MovePrevious 方法示例 (VB) MoveFirst, MoveLast, MoveNext, and MovePrevious Methods Example (VB)
MoveFirst、MoveLast、MoveNext 和 MovePrevious 方法示例 (VBScript) MoveFirst, MoveLast, MoveNext, and MovePrevious Methods Example (VBScript)
MoveFirst、MoveLast、MoveNext 和 MovePrevious 方法示例 (VC + +) MoveFirst, MoveLast, MoveNext, and MovePrevious Methods Example (VC++)
ADO (移动方法) Move Method (ADO)
MoveFirst、MoveLast、MoveNext 和 MovePrevious 方法 (RDS) MoveFirst, MoveLast, MoveNext, and MovePrevious Methods (RDS)
MoveRecord 方法 (ADO)MoveRecord Method (ADO)