记录集中循环的最快方法
我有一个 VB6 应用程序。我有 2 个记录集具有相同数量的记录(几乎 50k)。现在我必须循环 50k*50k *(字段数)。谁能告诉我最快的方法吗?
提前致谢。
I have a VB6 application. I have 2 recordsets having the same number of records (almost 50k). Now I have to loop 50k*50k *(number of fields). Can any one tell me the fastest way to do so?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如其他人指出的那样,在客户端执行此操作并不是一个好主意,但这里有一些加快记录集访问速度的指示。
以仅向前 (adOpenForwardOnly) 方式打开记录集,如果您不写入,则也只能读取。
按数字引用字段,因此您可以使用 rs.Fields(0),而不是执行 rs.Fields(“MyField”)
如果你要写回数据库,那么考虑将事情包装在事务中以加快速度。
循环时使用“Do Until rs.EOF”而不是计数记录。
这就是我现在能想到的,但他们应该有一点帮助
As others have pointed out it is not a good idea to do this client side but here are a few pointers for speeding up recordset access.
Open the recordset as forward only (adOpenForwardOnly) and if you are not writing then read only also.
Refer to the fields by number so instead of doing rs.Fields(“MyField”) you would use rs.Fields(0)
If you are writing back to the database then consider wrapping things up in a transaction to speed things up.
When looping use “Do until rs.EOF” instead of counting records.
Thats all I can think of for now but they should help a bit
在 vb6 中确实没有最快的方法来做到这一点。
您将使用 2 个 for 循环。
您可能想向我们提供更多详细信息,说明为什么您要下拉 50k 条记录(两次)并比较每个字段。这通常表明需要在数据库端完成某些操作,但已被带到客户端来解决。
There really is no fastest way to do this in vb6.
You'd use 2 for loops.
You might want to give us more details as to why you are pulling down 50k records (twice) and comparing each field. This is usually an indication that something needs to be done on the database side but was brought in to the client side to be solved.
如果您的两个数据库相同并且唯一的区别是数据,您可以执行以下操作(伪代码):
t1 和 t2 将是您的两个表。这不是最有效的,但它可以让您非常轻松地进行比较。此外,您在 SELECT 语句中显示的内容可能会变得更加复杂。目前它只是两列并排的列表。
If your two databases are the same and the only difference is the data, you could do something like this (pseudo-code):
t1 and t2 would be your two tables. This isn't the most efficient but it would allow you to do the comparisons very easily. Also, you could get more complicated with what you show in the SELECT statement. Currently it is just a listing of both columns side by side.
澄清您有两个需要比较的 Access 数据库后,最简单的方法是将两个数据库链接在一起,然后通过查询进行比较。
右键单击白色空白区域,
链接表
。找到第二个数据库,选择其中的表。
现在您可以编写一个查询来比较两者。通过链接拉取时,所比较的数据始终是最新的。
Having clarified that you've got two Access databases you need to compare, the easiest is to link the two together and then compare with a query.
Right-click the white empty space,
Link tables
.Locate you second DB, select the table in it.
Now you can write a query to compare the two. The data being compared is always up to date as it's being pulled through the link.
我已经编写了很多次代码来比较和同步两个数据表,并且我已经在 SO 上发布了相关内容。关键是使用 SQL 将结果限制为不匹配的记录,但主要的见解是一次编写一列的动态 SQL。在每个 SQL 语句上使用 WHERE 子句,这将比任何其他比较方法更有效。
在 Access 中,我编写了这段代码来从一个表更新另一个表。它假设两个表具有相同的字段,并且有一个 PK 字段实际上标识两个表中的相同记录。该代码依赖于我的 SQLRun() 函数来实际执行 SQL,但如果您不希望的话,可以用 CurrentDB.Execute 替换该行。
I have written code to compare and synchronize two data tables many, many times, and I've posted about it here on SO. The key is to use SQL to limit the results to the records that don't match, but the chief insight is to write your on-the-fly SQL ONE COLUMN AT A TIME. With a WHERE clause on each of your SQL statements, this will be much more efficient than any other comparison method.
Within Access, I've written this code to update one table from another. It assumes the tables have the same fields and that there's a PK field that actually identifies the same record in both tables. The code has a dependency on my SQLRun() function to actually execute the SQL, but that line could be replaced with CurrentDB.Execute if you don't want that.
尝试使用sql的算法,左连接和右连接,然后在vb中应用它..,
我也和你有同样的问题,但我尝试了这个解决方案,它有效..,首先,它需要几乎3完成查询需要几个小时,但是当我应用 sql 算法时,只需要几分钟
try to use the algorithm of sql., the left and right join., then apply it in vb..,
i also have the same problem with you but i try that solution and it works.., on first, it takes almost 3 hours the complete the query but when i apply the sql algo, it just takes few minis