How to Insert with Progress Bar in C#

Hello guyz. In this code show you on how to use the progress bar with Insert command.

First Step:

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "your connectionstring";

int i;
int x = 1000; //insert 1000 rows
Bar.Maximum = x; //Bar ( Your progressbar)

for (i = 0; i < x; i++)
string sQL = "Insert Into table1" & _ "(empid,dates,username) values ('COLLADO','11/4/1982','Sayre')";

OleDbCommand cmd = new OleDbCommand(sQL, conn);

Bar.Value = Bar.Value + 1;
pr = Bar.Value;
pr1 = pr / x;
pr2 = pr1 * 100;
lblpercent.Text = pr2.ToString(); //show the percent in label

//Get the total row in the table
string sQL1 = "select * from table1";
OleDbCommand cmd1 = new OleDbCommand(sQL1, conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd1);
string ss = ds.Tables[0].Rows.Count.ToString();

Hope this One Can Help.

Please Rate This Response, If its Informative.



Author: Nisar11 May 2009 Member Level: Gold   Points : 1

Sayre! nice piece of code, its simple but handy and useful code....
keep posting

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: