Hello,
I have a little windows application that opens a text file and line by line goes and updates a record on a sql database. I have a label that says "Importing IDs to KIS" and I set the cursor to wait cursor. I wanted to show the user the record number being updated so within my loop I have a line that updates the label in the form: label.text = "Record: " + Counter.ToString ();
The problem is that the label doesn't refresh until the end of the loop and I don't understand why. The code is displayed below, hope someone can explain to me why this is happening (or not happening
)
Thanks
Luis Torres
I have a little windows application that opens a text file and line by line goes and updates a record on a sql database. I have a label that says "Importing IDs to KIS" and I set the cursor to wait cursor. I wanted to show the user the record number being updated so within my loop I have a line that updates the label in the form: label.text = "Record: " + Counter.ToString ();
The problem is that the label doesn't refresh until the end of the loop and I don't understand why. The code is displayed below, hope someone can explain to me why this is happening (or not happening
Code:
private void ImportIDKIS_button_Click(object sender, EventArgs e)
{
FileStream fileImportKIS = new FileStream("C:\\ExportKISData.txt", FileMode.Open, FileAccess.Read);
StreamReader srRead = new StreamReader(fileImportKIS);
SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();
connection.ConnectionString = CodeValues.KIS;
connection.Open();
command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "SP_ImportPlanFromFile271";
string[] tokens;
int C = 0;
Import_label.Text = "Importing IDs to KIS";
Cursor = Cursors.WaitCursor;
while (srRead.Peek() >= 0)
{
C++;
tokens = srRead.ReadLine().Split('^');
command.Parameters.Add("@MedicaidID", SqlDbType.VarChar, 10);
command.Parameters["@MedicaidID"].Value = tokens[0];
command.Parameters.Add("@AuthorizationDate", SqlDbType.VarChar, 10);
command.Parameters["@AuthorizationDate"].Value = tokens[1];
command.Parameters.Add("@PlanKind", SqlDbType.VarChar, 10);
command.Parameters["@PlanKind"].Value = tokens[2];
command.Parameters.Add("@PlanType", SqlDbType.VarChar, 10);
command.Parameters["@PlanType"].Value = tokens[3];
command.Parameters.Add("@PlanName", SqlDbType.VarChar, 50);
command.Parameters["@PlanName"].Value = tokens[4];
command.ExecuteNonQuery();
command.Parameters.Clear();
[COLOR=red]Import_label.Text = "Importing IDs to KIS: " + C.ToString ();[/color]
}
connection.Close();
srRead.Close();
Cursor = Cursors.Default;
Import_label.Text = "Importing Done. Number of IDs Imported: " + C.ToString();
ImportIDKIS_button.Enabled = false;
}
Thanks
Luis Torres