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();
}
}
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()
{
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();
}