private void btnsave_Click(object sender, EventArgs e) { db = new db_MiletecDataContext(); if (txtUsername.Text != string.Empty && cmbSecretQuestion.Text != string.Empty && txtSecretAnswer.Text != string.Empty) { int flag = 0; string pass; db = new db_MiletecDataContext(); var query = db.sp_Retreivepass(txtUsername.Text, cmbSecretQuestion.Text, txtSecretAnswer.Text); foreach (sp_RetreivepassResult result in query) { pass = result.Password.ToString(); MessageBox.Show(pass, "your Password is", MessageBoxButtons.OK); txtUsername.Text = "Username"; lblsecretquestion.Text = "Secret_Question"; cmbSecretQuestion.SelectedItem = null; txtSecretAnswer.Text = "Secret_Answer"; flag++; } if (flag == 0) { MessageBox.Show("Invalid Account.", "NOTE", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUsername.Text = "Username"; lblsecretquestion.Text = "Secret_Question"; cmbSecretQuestion.SelectedItem = null; txtSecretAnswer.Text = "Secret_Answer"; } } else { MessageBox.Show("Please fill up everything!", "NOTE", MessageBoxButtons.OK, MessageBoxIcon.Error); } }