Reputation: 1
My concept is For example here[COU] =45
,then the progressbar load with that count and want to show completed successfully.
But am not getting the progress simultaneosly work with count here and does not show message also,please help me to do,my code is shown below
public void proget()
{
System.Data.DataRowView selectedFile =
(System.Data.DataRowView)dataGrid1.SelectedItems[i];
string iid = Convert.ToString(selectedFile.Row.ItemArray[10]);
SqlConnection con = new SqlConnection("Data Source=TNT3FMR\\SQLEXPRESS;Initial Catalog=xxx;Integrated Security=True");
string query = "SELECT [COU] FROM _Count_Series WHERE STUID='"+iid+"'";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
progressBar1.Value++;
}
MessageBox.Show("Completed Successfully");
}
Upvotes: 0
Views: 59
Reputation: 784
i'm not sure your design is right. best practices say you should close the db connection as soon as possible in a connected scenario. this means reading the data first and disposing of the reader before processing it. what you're doing is a little strange to me.
a problem i noticed in your code is that you build the query dynamically by concatenating strings. this opens you up to SQL injection attacks. you should use parametrized queries instead.
another problem is that you are not using the 'using pattern'. what happens if you get an error while connecting? how are the connection resources released?
from my personal experience, when i access a database i do it in an async manner and set the progressBar to an indeterminate state because i don't know how much it will take to read the data. your code is synchronous. this might be part of the reason why your UI doesn't update correctly.
hope this helps
Upvotes: 2