BOF、EOF 属性 (ADO)BOF, EOF Properties (ADO)

  • BOF 指示当前记录位置位于 记录集 对象中的第一条记录之前。BOF Indicates that the current record position is before the first record in a Recordset object.

  • EOF 指示当前记录位置在 Recordset 对象的最后一条记录之后。EOF Indicates that the current record position is after the last record in a Recordset object.

返回值Return Value

BOFEOF 属性返回 布尔 值。The BOF and EOF properties return Boolean values.

备注Remarks

使用 BOFEOF 属性来确定 recordset 对象是否包含记录,或者在从记录移到记录时是否超出 recordset 对象的限制。Use the BOF and EOF properties to determine whether a Recordset object contains records or whether you have gone beyond the limits of a Recordset object when you move from record to record.

如果当前记录位置在第一条记录之前,则 BOF 属性返回 True (-1) ; 如果当前记录位置位于第一条记录的前面或后面,则 为 False (0) 。The BOF property returns True (-1) if the current record position is before the first record and False (0) if the current record position is on or after the first record.

如果当前记录位置晚于最后一条记录,则 EOF 属性返回 True ; 如果当前记录位置位于最后一条记录之前,则返回 FalseThe EOF property returns True if the current record position is after the last record and False if the current record position is on or before the last record.

如果 BOFEOF 属性为 True,则没有当前记录。If either the BOF or EOF property is True, there is no current record.

如果打开的 记录集 对象不包含任何记录,则 BOFEOF 属性将设置为 True (查看 RecordCount 属性以获取有关 记录集 的此状态的详细信息) 。If you open a Recordset object containing no records, the BOF and EOF properties are set to True (see the RecordCount property for more information about this state of a Recordset). 如果打开的 记录集 对象至少包含一条记录,则第一条记录为当前记录, BOFEOF 属性为 FalseWhen you open a Recordset object that contains at least one record, the first record is the current record and the BOF and EOF properties are False.

如果您删除 记录集 对象中的最后一个记录,则 BOFEOF 属性可能会保持 为假 ,直到您尝试重新定位当前记录为止。If you delete the last remaining record in the Recordset object, the BOF and EOF properties may remain False until you attempt to reposition the current record.

此表显示了允许使用不同的 BOFEOF 属性组合的 移动 方法。This table shows which Move methods are allowed with different combinations of the BOF and EOF properties.

MoveFirstMoveFirst,

MoveLastMoveLast
MovePreviousMovePrevious,

移动 < 0Move < 0
移动0Move 0 MoveNextMoveNext,

移动 > 0Move > 0
BOF =TrueEOF = FalseBOF=True, EOF=False 然后用户才能访问Allowed 错误Error 错误Error 然后用户才能访问Allowed
BOF =FalseEOF = TrueBOF=False, EOF=True 允许Allowed 允许Allowed 错误Error 错误Error
为 TrueBoth True 错误Error 错误Error 错误Error 错误Error
为 FalseBoth False 允许Allowed 允许Allowed 允许Allowed 允许Allowed

允许 Move 方法并不保证该方法能够成功定位记录;这只意味着调用指定的 Move 方法不会生成错误。Allowing a Move method does not guarantee that the method will successfully locate a record; it only means that calling the specified Move method will not generate an error.

下表显示了在调用各种 Move 方法但无法成功定位记录时, BOFEOF 属性设置会发生什么情况。The following table shows what happens to the BOF and EOF property settings when you call various Move methods but are unable to successfully locate a record.

BOFBOF EOFEOF
MoveFirstMoveLastMoveFirst, MoveLast 设置为 TrueSet to True 设置为 TrueSet to True
移动 0Move 0 没有变化No change 没有变化No change
MovePreviousMove < 0MovePrevious, Move < 0 设置为 TrueSet to True 没有变化No change
MoveNext移动 > 0MoveNext, Move > 0 没有变化No change 设置为 TrueSet to True

应用于Applies To

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

另请参阅See Also

BOF、EOF 和 Bookmark 属性示例 (VB) BOF, EOF, and Bookmark Properties Example (VB)
BOF、EOF 和 Bookmark 属性示例 (VC + +) BOF, EOF, and Bookmark Properties Example (VC++)