Recordset 支持 BOF 和 EOF 属性来分别描述数据集的开始和结尾。 可以将 BOF 和 EOF 视为位于 Recordset开头和结尾的“幻影”记录。 计算 BOF 和 EOF,我们的示例 Recordset 现在如下所示:
| ProductID | ProductName | 单价 |
|---|---|---|
| 转炉 | ||
| 7 | 鲍勃叔叔的有机干梨 | 30.0000 |
| 14 | 豆腐 | 23.2500 |
| 28 | Rssle酸菜 | 45.6000 |
| 51 | 曼吉穆普干苹果 | 53.0000 |
| 74 | 长寿豆腐 | 10.0000 |
| EOF |
当游标移动过最后一条记录时,EOF 设置为 True;否则,其值 False。 同样,当游标在第一条记录之前移动时,BOF 设置为 True;否则,其值 False。 这些属性通常用于枚举数据集中的记录,如以下 JScript 代码片段所示。
while (objRecordset.EOF != true)
{
// Work on the current record.
...
// Advance the cursor forward to the next record.
objRecordset.MoveNext();
}
or
while (objRecordset.BOF != true)
{
// Work on the current record.
...
// Move the cursor to the previous record.
objRecordset.MovePrevious();
}
如果 BOF 和 EOF 都 True,则 Recordset 对象为空。 对于新打开的非空 Recordset 对象,两个属性都将为 False。 可以使用 BOF 和 EOF 属性来确定 Recordset 对象是否为空,如以下 JScript 代码片段所示。
if (objRecordset.EOF == true && objRecordset.BOF == true)
{
WScript.Echo("we got an empty dataset.");
}
else
{
WScript.Echo("we got a full dataset.");
}
此方案适用于所有类型的游标,独立于基础提供程序。 如果您尝试通过检查 RecordCount 属性值是否为零 (0) 来判断 Recordset 对象是否为空,必须确保选择一个适合的游标和提供程序,它们应支持返回结果中的记录数。
如果删除 Recordset 对象中的最后一条剩余记录,光标将处于不确定状态。 BOF 和 EOF 属性可能保持为 False 状态,这取决于提供程序,直到您尝试重新定位当前记录。 有关详细信息,请参阅 使用 Delete 方法删除记录。