如何显示进度条,将多个记录插入数据库 [英] How to display progress bar whilw inserting multiple records to database

查看:87
本文介绍了如何显示进度条,将多个记录插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在此先感谢,

在将多条记录插入数据库时​​,请提供用于显示进度条的示例代码,
使用for循环插入多个记录,在每个循环上将一条语句插入数据库,直到循环结束,我必须显示进度条才能实现此目标,请帮忙,


感谢Adavance,
Siva

Hi all,

Thanks in Advance,

Please give sample code for displaying the progress bar while inserting the multiple record to database,
Am insering multiple records by using for loop, on each loop an statement is inserted to database, untile the loop ends i have to display the progress bar how can i achive this, Please help,


Thanks in Adavance,
Siva

推荐答案

要通过进度条,您必须在使其可见的当前窗体上创建它,或者以单独的模式窗体(意思是在模式形式打开时不能与父形式交互).如果您希望进度条显示进度,那么除非将inster/delete/etc分解为单独的部分,否则您实际上无法进行数据库调用.基本上,您必须自己制作进度条.知道真正的进度可能很困难,这就是为什么很多时候您会看到进度条看起来不是线性的原因.很难知道真正的进展是什么.希望收到有关SQL调用的反馈,以取得进展.

另一件事是,您可能想使用BackgroundWorker在后台线程上执行SQL调用.建议您在网站上搜索后台工作人员的相同代码.这是一篇文章: BackgroundWorker线程和支持取消 [
In order to by a progress bar, you have to create it, either on the current form where you make it visible, or as a separate modal form (meaning cannot interact with parent form while modal form is open). If you want the progress bar to show progress, you really can''t with a database call unless you break the inster/delete/etc into separate parts. Basically you have to do the progress bar yourself. Knowing true progress can be diffucult, and this is why many times you will see progress bars that do not appear linear; it is difficult to know what the progress really is. Wish that there was a feedback on SQL calls that would give progress.

ANother thing is that you will want to do the SQL call on a background thread, probably using a BackgroundWorker. Suggest you search the site for sameple code for background workers. Here is one article: BackgroundWorker Threads and Supporting Cancel[^]

Hope this helps.




您的解决方案:
这很简单,请按照以下步骤操作.
Hi,

Your Solution :
This is very simple follow below steps.
1) Set Maximum value for Progress bar control with row count either from datatable or gridview etc..<br />
2) Set initial value to zero or minimum value of progress bar control.<br />
3) In your loop you need to increase your progress bar control''s value with 1.



示例代码:



Sample Code:

progressBar1.Maximum = dtTable.Rows.Count;
progressBar1.Value = progressBar1.Minimum;

foreach (DataRow vRow in dtTable.Rows)
{
    //TODO : Your INSERT, UPDATE, DELETE Or any Operation/Execution
    progressBar1.Value++;
}


这篇关于如何显示进度条,将多个记录插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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