Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label Not Refreshing...... Why? 1

Status
Not open for further replies.

Gixonita

IS-IT--Management
Oct 17, 2005
103
US
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 :))

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
 
Hi Luis,

While you're in the loop, the paint event for the label is not being called. Try placing an Application.DoEvents() after your line where you update the label.

Hope this helps,

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top