Click here to Skip to main content
15,888,590 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to show a progress bar while data is being inserted into a table. It takes around 1-2 mins.

C#
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");
           
        }
Posted
Updated 7-Sep-10 20:32pm
v2

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!
 
Share this answer
 
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
 
Share this answer
 
Hi shariq1,

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

I hope this link helpful to you.

Cheers :)
 
Share this answer
 
myProgressBar.Style = ProgressBarStyle.Marquee;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900