private void btnsave_Click(object sender, EventArgs e) { //if all fields are filled up if (lbloldpassword.Visible != true && lblnewpassword.Visible != true && lblconfirmnewpassword.Visible != true) { int stoper = 0; db = new db_MiletecDataContext(); var query_login = db.sp_verifyusernamepass(txtusername.Text, txtoldpass.Text); foreach (sp_verifyusernamepassResult entry in query_login.ToList()) { password = entry.Password.ToString(); username = entry.Username.ToString(); //if new password do not match if (txtconnewpass.Text != txtnewpass.Text) { MessageBox.Show("New Password does not match!", "NOTE", MessageBoxButtons.OK, MessageBoxIcon.Error); txtnewpass.Clear(); txtconnewpass.Clear(); } //if they match.. else { //if old password is correct if (txtoldpass.Text == password) { db.sp_changepass(txtusername.Text, txtnewpass.Text, txtoldpass.Text); MessageBox.Show("Successfuly Updated!!", "DONE", MessageBoxButtons.OK, MessageBoxIcon.Information); txtusername.Text = "Username"; txtoldpass.Clear(); txtnewpass.Clear(); txtconnewpass.Clear(); lbloldpassword.Visible = true; lblnewpassword.Visible = true; lblconfirmnewpassword.Visible = true; this.Close(); } } stoper++; } //if old password is incorrect, prompt message... if (stoper == 0) { MessageBox.Show("Incorrect old password!", "NOTE", MessageBoxButtons.OK, MessageBoxIcon.Information); } } //if some of the fields are empty else { MessageBox.Show("Please fill up everything", "NOTE", MessageBoxButtons.OK, MessageBoxIcon.Information); } }