Can you give this a shot? If it still doesnt run youll need to set break points in your app and step through it.
if (cboaccount1.Text == "" && cboaccount2.Text == "" && cbotitle.Text == "" && cboname.Text == "")
{
MessageBox.Show("Plz Provide Some Field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cboaccount1.Focus();
return;
}
if ((cbotitle.Text != "" ||cboname.Text!="") && !Regex.Match(cboaccount1.Text, @"^[0-9]{4}$").Success)
{
MessageBox.Show("Invalid Account NO\nShould be of type e.g 8459-5", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cboaccount1.SelectAll();
cboaccount1.Focus();
return;
}
if ((cbotitle.Text != "" ||cboname.Text!="") && !Regex.Match(cboaccount1.Text, @"^[0-9]{4}$").Success)
{
MessageBox.Show("Invalid Account NO\nShould be of type e.g 8459-5", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cboaccount1.SelectAll();
cboaccount1.Focus();
return;
}
if (!Regex.Match(cboaccount2.Text, @"^[0-9]{1}$").Success)
{
MessageBox.Show("Invalid Account No", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cboaccount2.SelectAll();
cboaccount2.Focus();
return;
}
if ((cboaccount1.Text != "" || cboaccount2.Text != "" || cbotitle.Text != "") && !Regex.Match(cboname.Text, @"^[A-Za-z][A-Za-z. ]*$").Success)
{
MessageBox.Show("Invalid Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cboname.SelectAll();
cboname.Focus();
return;
}
if ((cboaccount1.Text != "" || cboaccount2.Text != "" || cboname.Text != "") && !Regex.Match(cbotitle.Text, @"^[A-Za-z][A-Za-z. ]*$").Success)
{
MessageBox.Show("Invalid title", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cbotitle.SelectAll();
cbotitle.Focus();
return;
}
if ((cboaccount1.Text != "" || cboaccount2.Text != "" || cboname.Text != "") && !Regex.Match(cbotitle.Text, @"^[A-Za-z][A-Za-z. ]*$").Success)
{
MessageBox.Show("Invalid title", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cbotitle.SelectAll();
cbotitle.Focus();
return;
}
SqlCommand cmd = new SqlCommand("Select * from Accounts where Account_No='" + cboaccount1.Text + "-" + cboaccount2.Text + "'or Account_title= '" + cbotitle.Text + "'or Name='" + cboname.Text + "'", cn);
cmd.CommandType = CommandType.Text;
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "ss");
if (ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("No Record Exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
acse.dataGridView1.DataSource = ds.Tables["ss"];
this.Hide();
acse.ShowDialog();
this.Close();
}
If you have issues stepping through it let me know