显示从 MySQL 填充 DataSet 的进度 [英] Show progress of filling a DataSet from MySQL

查看:27
本文介绍了显示从 MySQL 填充 DataSet 的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 C# 和 MySQL 数据库后端开发应用程序.

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

我的程序最终可能会从数据库中加载大量数据并添加到要在 DataGridView 中显示的数据集中.我希望能够显示填充 DataSet 的进度,但不确定如何获取它在数据库中的位置的引用.

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.

推荐答案

我会用 Stecya 评论将进度条实现为选取框进度条.

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

为了能够更新数据集填充的进度条,您必须事先知道有多少条记录,然后继续做一些事情,例如包装 dataAdapter 以了解它已放入数据集中的记录数,我不完全确定你能做到.

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".

这篇关于显示从 MySQL 填充 DataSet 的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆