我想在查询数据库的时候用一下progressBar,一点效果都没有。
我的思路是在查询之前先打开定时器,定时器的事件里使progressBar进度增加,查询结束后关闭定时器。private void button3_Click(object sender, System.EventArgs e)
{
this.timer1.Enabled = true;
string SQL;
string countSQL;
if(radioButton1.Checked)
{
countSQL = "select count(*) from LCard where Campus='"+"武进校区"+"'and Statue='"+"新卡"+"'";
SQL = "select Code 卡号,Type 类型,Campus 校区,Statue 状态 from LCard where Campus='"+"武进校区"+"'and Statue='"+"新卡"+"'";;
}
else
{
countSQL = "select count(*) from LCard where Campus='"+"白云校区"+"'and Statue='"+"新卡"+"'";
SQL = "select Code 卡号,Type 类型,Campus 校区,Statue 状态 from LCard where Campus='"+"白云校区"+"'and Statue='"+"新卡"+"'";;
} string conStr = "server=(local);database=CardManage;Integrated Security=SSPI";
SqlConnection sqlCon = new SqlConnection(conStr);
SqlDataAdapter ad = new SqlDataAdapter(SQL,sqlCon); 
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(countSQL,sqlCon);
try
{
sqlCon.Open();
ad.Fill(ds,"LCard");
this.dataGrid.SetDataBinding(ds,"LCard");
////////显示总数
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
this.statusBar1.Text = "共有"+dr.GetValue(0).ToString()+"张新卡";
}
dr.Close();
}
catch(Exception ex)
{
MessageBox.Show("error"+ex.ToString());
sqlCon.Close();
}
finally
{
sqlCon.Close();
}

this.timer1.Enabled = false;
this.progressBar1.Value = this.progressBar1.Minimum;
}