如何测试记录集是否为空?

发布于 2024-11-26 05:34:16 字数 514 浏览 3 评论 0原文

如何测试记录集是否为空?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

伴我老 2024-12-03 05:34:16

我会检查“文件结束”标志:

If temp_rst1.EOF Or temp_rst2.EOF Then MsgBox "null"

I would check the "End of File" flag:

If temp_rst1.EOF Or temp_rst2.EOF Then MsgBox "null"
谁人与我共长歌 2024-12-03 05:34:16

如果 temp_rst1.BOFtemp_rst1.EOF 则记录集为空。对于空记录集、链接记录集或本地记录集始终如此。

If temp_rst1.BOF and temp_rst1.EOF then the recordset is empty. This will always be true for an empty recordset, linked or local.

逆蝶 2024-12-03 05:34:16

一个简单的方法是这样写:

Dim rs As Object
Set rs = Me.Recordset.Clone
If Me.Recordset.RecordCount = 0 then 'checks for number of records
   msgbox "There is no records" 
End if

A simple way is to write it:

Dim rs As Object
Set rs = Me.Recordset.Clone
If Me.Recordset.RecordCount = 0 then 'checks for number of records
   msgbox "There is no records" 
End if
居里长安 2024-12-03 05:34:16

如果不是 temp_rst1 则什么都没有...

If Not temp_rst1 Is Nothing Then ...

不醒的梦 2024-12-03 05:34:16

在这里,我使用 MS Access 2016,并使用以下命令检查记录集字段是否不为空:

If (RecordSt.Fields("field_name").Value) Then
' do what you want if there is returned data
Else 
' do what you want if there isn't any data returned by the select

Here, I'm using MS Access 2016 and I check if the recordset field if not null using this:

If (RecordSt.Fields("field_name").Value) Then
' do what you want if there is returned data
Else 
' do what you want if there isn't any data returned by the select
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文