Show progress of filling a DataSet from MySQL

别等时光非礼了梦想. 提交于 2019-12-06 00:19:52

I would go with Stecya comment an implement the progress bar as a marquee progress bar.

For you to be able to update a progress bar of the dataset fill, you would have to know how many records you have beforehand, then keep do something like wrapping the dataAdapter to know how many records it has put into the dataset, which I'm not entirely sure you could do.

If binding the dataSource takes a considerable amount of time as well, I would have a status message along with the marquee bar, and update it with "Retrieving records", then something along the lines of "Rendering records".

This answer might come a little late, but maybe it helps others.

In many cases it is sufficient to show the number of records read so far. That could be done by handling the DataTable.RowChanged-event. From a test implementation I could verify, that the event fires for each row added by the DataAdapter.Fill-Method. When handling the event you could get the number records read by looking at the DataTable.Rows.Count-Property

What I usually do is read the data in a background thread, that updates a label or listbox entry. The method that actually updates the gui buffers the updates to the label so that the gui changes occure only once a second to prevent flickering.

Hope this helps.

Sascha

Instead of

myDA.Fill(table);

... you should be able to fill the table row by row:

var dataReader = myDA.SelectCommand.ExecuteReader();
int progress = 0;
while (dataReader.Read()) {
   table.Rows.Add(dataReader);
   progress++;

   // Update progress view..
}

It's not as neat as using the Fill method though, so I'm not sure if you want to do it this way. And of course, in order to be able to show how many percent of the work is done, you will also need to get the number of rows in the table by "Select count" or similar, just as phsr pointed out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!