Here Is my class file function when it finds duplicate it shows messagebox but problem is that it does not stop by return statemtnt it also executes next queries on windows form
Code On Class File
public void FindDuplicate(String sql, string message)
{
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show(message, "Duplicate Record", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else
{
// MessageBox.Show("No Records Found","No Record Found",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
Code On Windows Form
db.FindDuplicate("Select * from Supplier_Details WHERE Sup_Name='"+txtSupplierName.Text+"'", "Name Already Exist");
If Record Found Then Shows MessageBox But Also Executes Next Statements I want to stop Here till User Enter Non-Duplicate Name
if (txtSupplierName.Text == "" || txtContactNo.Text == "" || txtAddress.Text == "")
{
MessageBox.Show("Please Fill All Details", "Empty TextBoxes", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
db.WriteLog("Empty TextBoxes: " + " " + txtSupplierID.Text + " ");
return;
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Amit GuptaPosted Jul 9, 2017, 8:51 AM
Murli JadhavPosted Jul 9, 2017, 12:39 PM