Reputation: 1734
I have a VB.NET Application. In the same have some query, which result will display in a DataGridView. It need 2 to 3 min to execute my query. Now I want to show a Progressbar on Status bar that will display the Data Retrieve progress . After Complete, it will hide from Statusbar and a Label will show "Completed". If any expert help me I will be thankful to him.
Upvotes: 1
Views: 1511
Reputation: 12169
You question covers a lot of ground. The first thing that comes to my mind is, why do you have a query that takes so long to run, and can it be optimized? How bit is the data set you are returning? 10 rows, 100s rows, 100000s? If the dataset is large, are you using pagination? ADO.Net does provide an async interface model, see here Async SQLCommand. One possibility is to issue your query async then show your progress bar, and close the progress bar when you get a completed notification.
Another option is to start the query in another thread, but that is probably not needed if you can use the async SQLCommand. However, if you want to show a progress bar that updates to show %complete, as opposed to a "waiting" indicator, that will be challenging. For one thing, you have no clue as to how long the query will take. It is not a deterministic process such as reading a file from disk, where you can estimate file size, transfer speed, etc. I do not think there is any mechanism in SQL server to query, "how's my query going?" A poor and wasteful alternative would be to first run one query to get the count of records you expect, then divide the fetching query into smaller subqueries with some range parameter and execute in "chunks". Again, that is not efficient. Maybe someone knows of alternatives.
Upvotes: 2