Show the progress of populating a DataSet from MySQL

I am currently developing an application using C # and MySQL Database Backend.

My program can eventually load a large amount of data from the database and add it to the data set that will be displayed in the DataGridView. I want to show the progress of filling the DataSet, but I don’t know how I can get a link to where it is in the database.

Below is the code that I 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 the stream as a background worker, but how can I change this code to show the progress.

+3
source share
3 answers

I would go with Stecya to comment on the implementation of the progress bar as an indicator of the progress of the step.

, , , - dataAdapter, , , , .

dataSource , " ", - "Rendering records".

0

, , , .

, . , DataTable.RowChanged. , , DataAdapter.Fill-Method. , DataTable.Rows.Count-Property

, . , gui-, , gui , .

, .

+4

myDA.Fill(table);

... :

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, so I'm not sure if you want to do it this way. And, of course, to show how much percent of the work has been done, you will also need to get the number of rows in the table by selecting "Select Account" or similar, as indicated in phsr.

+1
source

Source: https://habr.com/ru/post/1795100/