Click here to Skip to main content
15,886,518 members

form hangs when implementing my logic

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#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

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.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900