gpt4 book ai didi

sql - 如何从 ADO 查询中获取记录数?

转载 作者:行者123 更新时间:2023-12-03 15:27:31 25 4
gpt4 key购买 nike

Possible Duplicate:
How to see progress of query execution during handle?

我想显示一个进度条,指示从数据库获取结果需要多长时间。

我使用TADOQuery并以异步模式打开它。而查询状态为stFetching ,有什么办法可以知道[获取的记录数/总记录数]吗?

最佳答案

OnFetchProgress 编写一个处理程序事件。来自引用:

Write an OnFetchProgress event handler to take specific action during an asynchronous data retrieval operation. The OnFetchProgress event fires periodically during the data retrieval to provide indications of its progress. Create a handler for this event to react to this periodic notification, such as providing the user with a visual indication of the progress of the data retrieval.

请注意,将传递给 OnFetchProgress 事件的 MaxProgress 值是最佳猜测。来自 How To Use the ADO FetchProgress and FetchComplete Events :

MaxProgress is not equal to the actual number of records that will be returned. ADO has to fetch the records in order to get this value. This means MaxProgress is only ever a best guess. MaxProgress usually equals Progress plus Background Fetch Size.

您可以向数据库发出 Select Count() ..,如 Diego 的 answer 中所述。在打开查询之前获取要检索的记录的准确总数,但这并不总是可取的,因为它可能会导致冗余的表扫描和复杂查询的大量执行时间。

关于sql - 如何从 ADO 查询中获取记录数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12970913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com