Write a handler for the OnFetchProgress event. From the reference:
Write an OnFetchProgress event handler to perform certain actions during an asynchronous data retrieval operation. The OnFetchProgress event is fired periodically when data is retrieved to ensure its progress. Create a handler for this event to respond to this event. periodic notification, for example, providing the user with a visual indication of data retrieval progress.
Note that the MaxProgress value that will be passed to the OnFetchProgress event is the best guess. From How to Use the ADO Events of FetchProgress and FetchComplete :
MaxProgress is not equal to the actual number of records that will be returned. ADO must receive records in order to get this value. This means that MaxProgress is just the best guess. MaxProgress is usually equal to Progress plus the background sample size.
You can send Select Count() .. to the database, as indicated in the Diego answer , before opening your query to get the exact total number of records to be retrieved, but this is not always advisable, as this may lead to over-scanning of the table and significant runtime of complex queries.
source share