如何测试记录集是否为空?
如何测试记录集是否为空?
Dim temp_rst1 As Recordset
Dim temp_rst2 As Recordset
Set temp_rst1 = db.OpenRecordset("SELECT * FROM ORDER_DATA WHERE SKUS_ORDERED = '" & curSKU1 & "' AND [ORDER] = " & curOrder)
Set temp_rst2 = db.OpenRecordset("SELECT * FROM ORDER_DATA WHERE SKUS_ORDERED = '" & curSKU2 & "' AND [ORDER] = " & curOrder)
If IsNull(temp_rst1) Or IsNull(temp_rst2) Then MsgBox "null"
我正在根据 select 语句打开几个记录集。如果没有记录,IsNull会返回true吗?
How do I test if a Recordset is empty?
Dim temp_rst1 As Recordset
Dim temp_rst2 As Recordset
Set temp_rst1 = db.OpenRecordset("SELECT * FROM ORDER_DATA WHERE SKUS_ORDERED = '" & curSKU1 & "' AND [ORDER] = " & curOrder)
Set temp_rst2 = db.OpenRecordset("SELECT * FROM ORDER_DATA WHERE SKUS_ORDERED = '" & curSKU2 & "' AND [ORDER] = " & curOrder)
If IsNull(temp_rst1) Or IsNull(temp_rst2) Then MsgBox "null"
I'm opening up a couple of Recordsets based on a select statement. If there are no records, will IsNull return true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会检查“文件结束”标志:
I would check the "End of File" flag:
如果
temp_rst1.BOF
和temp_rst1.EOF
则记录集为空。对于空记录集、链接记录集或本地记录集始终如此。If
temp_rst1.BOF
andtemp_rst1.EOF
then the recordset is empty. This will always be true for an empty recordset, linked or local.一个简单的方法是这样写:
A simple way is to write it:
如果不是 temp_rst1 则什么都没有...
If Not temp_rst1 Is Nothing Then ...
在这里,我使用 MS Access 2016,并使用以下命令检查记录集字段是否不为空:
Here, I'm using MS Access 2016 and I check if the recordset field if not null using this: