I want to insert a progress bar so that while reader don't complete reading data from database it progress toword it's completion. The code is given following
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.IO;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ETL_Tool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\ptcl_1.accdb";
OleDbConnection conn = new OleDbConnection(connectionString);
string sql = "SELECT * FROM 51";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
TextWriter tw = new StreamWriter("D:\\data.txt");
OleDbDataReader reader;
reader = cmd.ExecuteReader();
while (reader.Read())
{
//Some operation is performed here
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
Loading
theLizardPosted Dec 10, 2011, 10:06 PM
ProgressBar1.Max = (int)cmd.ExecuteScalar();
In your while loop ProgressBar1.Position++;
Too easy...
Satyapriya NayakPosted Dec 10, 2011, 9:29 AM
Here is a similar example below
try this....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Login_Form_in_Csharp_Using_ProgressBar
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
//user id=u1,password=raj
public Form1()
{
InitializeComponent();
}
private void btnlogin_Click(object sender, EventArgs e)
{
if (txtusername.Text == "" || txtpassword.Text == "")
{
MessageBox.Show("Please enter User ID or Password");
txtusername.Text = "";
txtpassword.Text = "";
}
else
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select count(*) from login where userid='" + txtusername.Text.Trim() + "' and password='" + txtpassword.Text.Trim() + "'";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
oledbda.Fill(ds, "login");
long x;
x = Convert.ToInt64(com.ExecuteScalar());
if (x == 1)
{
int y = 0;
progressBar1.Visible = true;
progressBar1.Minimum = 1;
progressBar1.Maximum = 100000;
progressBar1.Value = 1;
progressBar1.Step = 1;
for (y = 1; y <= 100000; y++)
{
progressBar1.PerformStep();
}
Form2 f1 = new Form2();
f1.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid User ID or Password! Try Again!");
txtusername.Text = "";
txtpassword.Text = "";
}
con.Close();
}
}
}
}
Thanks
If this post helps you mark it as answer