VBA 中的记录集是什么?……它有什么用途?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2338978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a Recordset in VBA? ... what purpose does it serve?
提问by Alan_AI
What is a Recordset
in VBA?
Recordset
VBA中的a是什么?
What purpose does it serve?
它的目的是什么?
How do you use them?
你如何使用它们?
回答by Fionnuala
This is quite a large question. Briefly, a recordset is a selection of records from a table or query. Depending on the query used, it can be used to add, edit, delete and manipulate records. A recordset can be obtained using ADO or DAO and may have different methods and properties accordingly. Sticking to DAO, which is native to Access:
这是一个相当大的问题。简而言之,记录集是从表或查询中选择的记录。根据所使用的查询,它可用于添加、编辑、删除和操作记录。可以使用 ADO 或 DAO 获取记录集,并且可能具有相应的不同方法和属性。坚持使用 Access 原生的 DAO:
Dim rs As DAO.Recordset
Set rs=CurrentDB.OpenRecordset("Select ID, Company From Companies")
rs.Edit
rs!Company="ABC"
rs.Update
rs.AddNew
rs!Company="ABC"
rs.Update
Do While Not rs.EOF
If rs!Company="ABC" Then
''Do something
End If
rs.MoveNext
Loop
Set rs=Forms!SomeForm.RecordsetClone
rs.FindFirst "Company='ABC'"
If Not rs.NoMatch Then
Forms!SomeForm.Bookmark=rs.Bookmark
End If
回答by Gabriel McAdams
A recordset is basically an in-memory container for data. You use it to manipulate data, or to pass data around.
记录集基本上是数据的内存容器。您可以使用它来操作数据或传递数据。
When you read data from the database in VBA, the result will be in a recordset (with the exception of scalar data).
当您在 VBA 中从数据库读取数据时,结果将在记录集中(标量数据除外)。
回答by JeffO
Gabriel gave an excellent description of a recordset.
Gabriel 对记录集进行了出色的描述。
Databases are built to use set theory to interact with the data, but a recordset is a way to also work with the data procedurally. This code looks more like programming. The "MoveNext" method is an example where you can step through the data and work with one record one at a time.
建立数据库是为了使用集合论与数据交互,但记录集也是一种程序化处理数据的方式。这段代码看起来更像是编程。“MoveNext”方法是一个示例,您可以在其中逐步浏览数据并一次处理一个记录。
See Remou's code to implement DAO recordsets.
请参阅 Remou 的代码以实现 DAO 记录集。