ta mu

ta mu

  • NA
  • 201
  • 81.4k

if else logic error

Aug 26 2013 11:52 PM
i am using this code for searching against diffrent parameters. but when i enter wrong record error messag is shown "not found" when i enter valid record it populated to datagridview and agin error messag shown not found i whant to remove it. but when i remove it from current place then on wrong entry no error is shown help me plz.
 if (comboBox1.SelectedItem.ToString() == "Acc_No")
  {


  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where Account_no= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;


  my.Close();

  }

  if (comboBox1.SelectedItem.ToString() == "Name")
  {


  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where Name= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;


  my.Close();

  }
  if (comboBox1.SelectedItem.ToString() == "CNIC")
  {
  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where CNIC_no= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;

  my.Close();

  }
  if (comboBox1.SelectedItem.ToString() == "Contact No")
  {
  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where Phone_No= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;

  my.Close();

  }
  if (comboBox1.SelectedItem.ToString() == "Registration No")
  {
  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where Registration_no= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;

  my.Close();

  }


  if (comboBox1.SelectedItem.ToString() == "Frame No")
  {
  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where Frame_no= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;

  my.Close();
  }



  if (comboBox1.SelectedItem.ToString() == "Engine No")
  {
  my.Open();

  SqlDataAdapter da = new SqlDataAdapter("Select * from addcustomer where Engine_no= '" + textBox1.Text + "'", my);
  da.Fill(dt);
  dataGridView1.DataSource = dt.DefaultView;

  my.Close();

  }

  else
  {
  MessageBox.Show("No record found");
  my.Close();

  }


Answers (10)