I want to use progress bar to show the current progress % the rows of data have been loaded. I see similiar question has been asked in SO, but the solution is just suggest using marquee style.
For example, I run a Select statement that query a large data table which might take few seconds.
I want the progress bar update the current progress of the query. Is that possbile?
I know there is few things I need:
- A count of total records will be retrieving. (Can obtain by Select count(1) first)
- Some notificiation to tell how many records I just retrieved.
For 2. is the part I don’t know how to implement.
I can think of split it into couples query, but this may not be possible all the time.
But how about something similiar to Cursor in SQL? Ask SQL Server to query a chunk and returns data and repeatly.
for loop{
//query a chunk of records
//return
//Next
}
So I can caculate the progress and fill them into a single DataTable.
Is it possible to do something above? If so, how?
Because I seen an ASP.NET applicateion able to show the progress of loading a large data table, so I want to implement the same thing in WPF.
First, you need to be certain breaking the query into two isn’t going to double your querying time. You may find yourself waiting a couple of seconds before you get the record count, and you haven’t solved anything.
You could execute both queries in parallel (databases love concurrency and handle it very well), but you’ll be putting an extra burden on the database, which could become a scalability issue in the future.
As for querying in chunks, I believe the
SqlDataReaderwill allow you to fetch records as they become available, without first waiting for the entire query to complete. You’ll have to add them to the DataTable yourself, though.