Click here to Skip to main content

sariqkhan asked:

Open original thread
in this code. when user clicks on the submit button without filling both the text fields error message is delivered. but i used a picturebox when the password matches then a pitcturebox is shown to user which contains a tick sign. but the problem is when user clicks the submit button without filling both the fields the picturebox is visible. so i have written method
newval();
which checks for blank textfields of both the text fields and set the piturebox to false. but when i implement the code m form hangs up!1
 private void button1_Click(object sender, EventArgs e)
        {
            bool vcom = doublepasword();
            bool vnames = ValidateNames();
            bool vnames2 = ValidateNames2();
            if (!vcom && !vnames&& !vnames2)
            {
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project\sample project\prject xample2 perfect\login\Database1.mdf;Integrated Security=True;User Instance=True";
                try
                {
                  
                        conn.Open();
                        string qry2 = "UPDATE Table1 SET Password =@Password WHERE username=@username";
                        SqlCommand com = new SqlCommand(qry2, conn);
                        com.Parameters.AddWithValue("@username", this.label1.Text);
                        com.Parameters.AddWithValue("@Password", this.textBox1.Text);
                        int result = com.ExecuteNonQuery();
                        if (result > 0)
                        {
                            MessageBox.Show("updated sucesfull \n" + "your new password is: " + textBox1.Text + " thanks for changing your password", "success");
                            this.Hide();
                            login ls = new login();
                            ls.Show();
                           
                        }
                        else
                        {
                            MessageBox.Show("updated failed");
                           
                        }
 
                    }
                catch (Exception)
                {
                    MessageBox.Show("Error with the databse connection");
                }
            }
            else
            {
                MessageBox.Show("error");
                validation2();
               neval(); //when i comment this my form runs smoothly but when i uncomment this my form hangs up?? whats the problem in methods??
            }
        }
        public bool ValidateNames()
        {
            if (textBox1.Text == string.Empty)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        public bool ValidateNames2()
        {
            if (textBox2.Text == string.Empty)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public void neval()// is there any problem in this method?
        {
            while (textBox2.Text == "")
            {
                if (textBox1.Text ==  "")
                {    
                    pictureBox1.Visible = false;
                }
            }
        }
        private bool doublepasword()
        {
            if (textBox1.Text != textBox2.Text)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool validation2()
        {
            bool stat1 = doublepasword();
            if (stat1 == true)
            {
                errorProvider1.SetError(textBox2, "password doesnt match");
                pictureBox1.Visible = false;
                
                return true;
            }
            else
            {
                pictureBox1.Visible = true;
                
                errorProvider1.SetError(textBox2, string.Empty);
                return false;
            }
        }
       
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            validation2();
        }
Tags: C#

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100