I am currently developing an application using C# and a MySQL Database Backend.
My program could end up loading a large amount of data from the database and adding into a dataset to be displayed in a DataGridView. I want to be able to show the progress of the filling of the DataSet but not sure how I can get a reference to where it is in the database.
Below is the code that I currently have.
DatabaseWork dbase = new DatabaseWork();
try
{
dbase.openConnection();
MySqlDataAdapter myDA = new MySqlDataAdapter();
myDA.SelectCommand = new MySqlCommand(query, dbase.conn);
DataTable table = new DataTable();
myDA.Fill(table);
BindingSource bSource = new BindingSource();
bSource.DataSource = table;
tblDetails.DataSource = bSource;
//tblGrid.Columns[0].Visible = false;
}
catch (MySqlException ex)
{
dbase.displayError(ex.Message, ex.Number);
}
finally
{
dbase.closeConnection();
}
I know that I will have to put this section of code into a Thread like a Background Worker but how can I change this code to show the progress.
解决方案
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".