从DAO jet数据库获取不正确的记录数 [英] Getting an incorrect recordcount from a DAO jet database
问题描述
我正在尝试修改一些使用DAO Jet数据库的旧版VB6代码。
问题是RecordSet RecordCount属性。
数据库包含17953条记录。
代码执行MoveFirst和MoveLast,假设设置了RecordCount,但RecordCount属性只返回17855(98短)
代码然后将所有17953记录加载到ListView中,因此所有记录都被访问并正确加载到Listview中,但即使这样,RecordCount仍然只返回17855 !
还有其他办法让RecordCount正确吗?
什么我试过了:
简化代码是这样的。
Dim Dsi作为DAO.Recordset
设置Dsi = Dbs.OpenRecordset(tblMessages,dbOpenTable)
...
Dsi.MoveLast
Dsi.MoveFirst
...
'简单循环
直到Dsi.EOF
(将记录加载到ListView中)
Dsi.MoveNext
循环
...
I am trying to modify some old legacy VB6 code that uses a DAO Jet database.
The problem is the RecordSet RecordCount property.
The database contains 17953 records.
The code does a MoveFirst and MoveLast, which is supposed set the RecordCount, but the RecordCount property only returns 17855 (98 short)
The code then loads ALL the 17953 records into a ListView, so all records are accessed and are correctly loaded into the Listview, but even then the RecordCount still only returns 17855 !
Is there any other way to get the RecordCount to be correct?
What I have tried:
The simplified code is something like this.
Dim Dsi As DAO.Recordset
Set Dsi = Dbs.OpenRecordset(tblMessages, dbOpenTable)
...
Dsi.MoveLast
Dsi.MoveFirst
...
'Simple loop
Do Until Dsi.EOF
(load record into ListView)
Dsi.MoveNext
Loop
...
推荐答案
首先检查数据库:
Start by checking the database:
SELECT COUNT(*) FROM MyTable
将告诉您有多少行。使用Access运行查询,看看你得到了什么。猜测 - 并且无法访问您的数据库,它可能是 - 您将ID号与行号混淆,并且ID已删除行中的间隙。
并且帮助您的用户:不要只将18,000行转储到任何显示控件中:它不是人类的管理编号。选择它,让它们进行搜索,过滤它:但显示超过50行是不合理的,因为找到你感兴趣的行需要很长时间。而且它会使你的应用变慢。将两者结合起来,你的用户就会讨厌这个应用程序,这是有充分理由的。
will tell you how many rows there are. Use Access to run the query and see what you get back. At a guess - and without access to your DB that's all it can be - you are confusing an ID number with a row number, and there are "gaps" in the IDs where rows have been deleted.
And do your users a favour: Don't just dump 18,000 rows into any display control: it's not a management number for humans. Page it, let them search it, filter it: but displaying much more than 50 rows is unreasonable because it takes too long to find the row you are interested in. And it makes your app slow. Combine the two, and your users will hate the app, and for good reason.
这篇关于从DAO jet数据库获取不正确的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!