简体   繁体   English

如果我不创建记录集对象,是否需要在MS Access中关闭记录集?

[英]Do I need to close a recordset in MS Access if I don't create a recordset object?

I've read that it's important to close recordset objects in Access, but with my code, I never create a recordset object, I always just use an inline reference, eg: 我已经读过在Access中关闭记录集对象很重要,但是对于我的代码,我从不创建记录集对象,我总是只使用内联引用,例如:

Dim ClientName As String

ClientName = CurrentDB.OpenRecordset([some SQL]).Fields(0).Value

I can't see anything like CurrentDB.CloseRecordset, and I don't think CurrentDB.Close is a good idea. 我看不到像CurrentDB.CloseRecordset这样的东西,我不认为CurrentDB.Close是个好主意。 Do I need to close any recordset in this case, or does it do that automatically? 在这种情况下,我是否需要关闭任何记录集,还是自动执行此操作?

I'm using MS Access 2007 with an SQL Server backend via an ODBC connection. 我通过ODBC连接使用MS Access 2007和SQL Server后端。

If any of my terminology or use of such is wrong, feel free to correct me! 如果我的任何术语或使用此类错误,请随时纠正我!

Apparently CurrentDB.OpenRecordset 'appends to the recordset collection' 显然,CurrentDB.OpenRecordset'附加到记录集集合'

So does this code work, and does it indicate you have added to the recordsets collection: 这段代码也是如此,它表明你已经添加到记录集集合中:

Dim ClientName As String

msgbox CurrentDB.Recordsets.Count

ClientName = CurrentDB.OpenRecordset([some SQL]).Fields(0).Value

msgbox CurrentDB.Recordsets.Count

and going out on a limb, does this work: 并且走出困境,这是否有效:

Dim ClientName As String

msgbox CurrentDB.Recordsets.Count

ClientName = CurrentDB.OpenRecordset([some SQL]).Fields(0).Value

msgbox CurrentDB.Recordsets.Count

msgbox CurrentDB.Recordsets(0).Close

Your code creates an ephemeral recordset; 您的代码会创建一个短暂的记录集; it goes out of scope immediately after the statement has completed. 声明完成后立即超出范围。 So you can't .Close the recordset because it no longer exists. 所以你不能。 .Close记录集,因为它不再存在。

The situation is similar to this Immediate window session ... 情况类似于此立即窗口会话...

? CurrentDB.Recordsets.Count
 0 
strSelect = "SELECT Count(*) FROM Dual;"
MyVar = CurrentDB.OpenRecordset(strSelect)(0)
? MyVar
 1 
? CurrentDB.Recordsets.Count
 0 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MS Access-如何在一个记录集中聚合两个查询? - MS Access - how can i aggregate two queries in one recordset? 我是否需要多个游标对象来循环记录集并同时更新? - Do I need multiple cursor objects to loop over a recordset and update at the same time? 如何连接到数据库并在 C# 中循环记录集? - How do I connect to a database and loop over a recordset in C#? 将Complete RecordSet插入其他数据库MS Access中的另一个表 - Insert Complete RecordSet to another table in other database MS Access 如何在MS Access 2013中创建“ IN”验证规则 - How do I create an 'IN' validation rule in MS Access 2013 使用VB.NET更新访问记录集 - Update access recordset using VB.NET 记录集使用 - recordset using Postgres - 我没有超级用户,我无法创建角色,或者我无法以超级用户身份授予任何其他用户访问权限 - Postgres - I don't have a superuser and I can't create a role or I can't grant access to any other user as a superuser 如何在MS Access表单中创建一个按钮,然后创建一个日期戳,然后不允许进行进一步的编辑? - How do I make a button in an MS Access form create a date stamp, THEN not allow further edits? 如果我不在Android中关闭数据库会发生什么? - What would happen if I don't close the database in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM