DAO.Recordset 在 codese 中执行时仅返回一条记录

发布于 2024-12-27 02:12:54 字数 250 浏览 2 评论 0原文

该语句每次执行时总是只返回一条记录,

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select book_name from book")
Dim i As Integer
For i = 0 To rs.RecordCount - 1
lbBooks.AddItem rs!book_name
rs.MoveNext
Next

这可能是什么原因

This statement always returns only one record everytime when its executed

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select book_name from book")
Dim i As Integer
For i = 0 To rs.RecordCount - 1
lbBooks.AddItem rs!book_name
rs.MoveNext
Next

what could ebe the cause

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

一袭白衣梦中忆 2025-01-03 02:12:54

我相信 RecordsetRecordCount 属性会动态设置为从游标读取的数据量。即第一次打开时设置为1;如果您执行rs.MoveLast,它会将其设置为集合中的实际记录数。但是,您会遇到返回到开头的问题:您必须以特定模式打开记录集(我忘记了,从头到尾)才能任意前后移动光标指针。

迭代游标的常用方法是使用 while 循环,检查游标的文件末尾:

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select book_name from book")
Dim i As Integer

i = 0 
While Not rs.EOF
  lbBooks.AddItem rs!book_name
  rs.MoveNext
  i = i + 1
Wend

I believe that the RecordCount property of a Recordset is set dynamically to the amount of data that has been read from the cursor. That is, when it's first opened, it's set to 1; if you do rs.MoveLast, it will set it to the actual number of records in the set. However, you then have the problem of moving back to the start: you must have the recordset opened in a particular mode (which I forgot, from the top of my head) to be able to arbitrarily move the cursor pointer back and forward.

The usual way of iterating through a cursor is to use a while loop, checking for the cursor's end of file:

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Select book_name from book")
Dim i As Integer

i = 0 
While Not rs.EOF
  lbBooks.AddItem rs!book_name
  rs.MoveNext
  i = i + 1
Wend
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文