如何使用进度条? [英] How to use Progress bar ?

查看:179
本文介绍了如何使用进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在将数据插入表中时显示进度条.大约需要1-2分钟.

I want to show a progress bar while data is being inserted into a table. It takes around 1-2 mins.

private void button1_Click_1(object sender, EventArgs e)
        {
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection(@"Data Source=HAIDER-IT;Initial Catalog=csoft;Integrated Security=True");
                conn.Open();
                SqlCommand cmd = new SqlCommand("Search",conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandTimeout = 1800;
                cmd.Parameters.Add("@P_prd", SqlDbType.VarChar, 50).Value = "11";
                cmd.Parameters.Add("@P_rep", SqlDbType.VarChar, 50).Value = "31";
                cmd.Parameters.Add("@P_yy", SqlDbType.VarChar, 50).Value = "2008";
                cmd.Parameters.Add("@P_mm", SqlDbType.VarChar, 50).Value = "04";
                cmd.Parameters.Add("@P_HS", SqlDbType.VarChar, 50).Value = "1";
                int I = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
          
              MessageBox.Show("Data Inserted");
           
        }

推荐答案

进度条的问题在于它们是面向任务的,而不是面向时间的.例如,如果您要处理100个项目,则可以将进度条的最大值设置为100,然后从1开始,并在每次开始处理新项目时递增.代码基本上只执行了一点SQL ...即一项任务.最大值1,从1开始,无处可增加!
The issue with progress bars is that they are task oriented, not time oriented. For example, if you had 100 items to process, you might set your progress bar max value to 100, then start at 1 and increment every time you start processing a new item... Your code basically has a single bit of SQL being executed... ie: one task. Max value 1, start at 1, nowhere to increment to!


以异步模式执行查询.每两秒钟增加一次进度条(我知道这是个骗子),因为您无法真正知道或知道SQL语句何时将完成执行.查询停止后,将进度条填满.顺便说一句,从工具箱中拖动进度栏,然后使用progressBar1.Value
Execute the Query in Asynchronous mode. Increment the progress bar every two seconds (I know this a cheat) because you can''t really know or tell when the SQL statement is going to finish executing. After the query stops, then make the progress bar full. BTW, drag the progress bar from the toolbox, and set values on it with progressBar1.Value


Hi shariq1,
在其上设置值
http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbar.value.aspx [ ^ ]

希望此链接对您有所帮助.

干杯:)
Hi shariq1,

http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbar.value.aspx[^]

I hope this link helpful to you.

Cheers :)


这篇关于如何使用进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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