When I run my code it is not exit(return) method according to my code. I am using two different classes and when I click on the button, it is running from one method to another method and it does not exit(return) the method.
class FormAction
{
DBConnection dbCon = new DBConnection();
public void txtBoxValidate(Control txtBoxName, string msg, Control frmName)
{
if (String.IsNullOrEmpty(txtBoxName))
{
MessageBox.Show(msg, MsgBoxStyle.Exclamation, frmName.Text);
txtBoxName.Focus();
return;
}
}
public void ValChkDubANDexe(string sqlSTR_Chk, string sqlSTR_exe, Control frmName)
{
dbCon.ExecuteSQLQuery(sqlSTR_Chk);
if (dbCon.sqlDT.Rows.Count > 0)
{
MessageBox.Show("Item Already Exist in Database", frmName.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
dbCon.ExecuteSQLQuery(sqlSTR_exe);
MessageBox.Show("Data Has Been Saved.", frmName.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
FormReset frmReset = new FormReset();
FormAction frmAct = new FormAction();
private void btnSave_Click(object sender, EventArgs e)
{
string sqlSTR_Chk;
string sqlSTR_exe;
frmAct.txtBoxValidate(TextBox1, "Please Enter The Age.", this);
sqlSTR_Chk = "SELECT * FROM Table1 WHERE Field1 = '" + TextBox1 .Text + "'"; //Dublicate Check
sqlSTR_exe = "INSERT INTO Table1(Field1) VALUES('" + TextBox1 .Text + "')";
frmAct.ValChkDubANDexe(sqlSTR_Chk, sqlSTR_exe, this);
frmReset.ResetAllControls(this);
}
If I click on the button while TextBox1
is empty I'm getting error message from txtBoxValidate
as expected but the code isn't return(exit) and it is continues to execute the query.
and also if TextBox1
is not empty and also if I try to execute the query with duplicate value it is catching the duplicate and it is going for next method(reset form).
So, Please help me to stop execute the query if the TextBox1
is empty. and Stop the to form reset if query execute found a duplicate.