title: Implementing database search
body: <p>I use mysql as database where I store my data.<br></p>
  
  <p>I have a windows form with textboxes radiobuttons, comboboxes and more; where people give personal information about themselves like (first name, last name, sex, date birthday, phone, father name and more like this). (40 fields total)<br></p>
  
  <p>I want to do a search button. With this button I want to fill some fields and after I push the search button a new window be opened containing all people with same personal information. I achieved to do a search button for one field (for example searching only by name).</p>
  
  <p>But I have a problem when I select to search with more than one fields. For example I select to search all people who have name:Chris, Nickname:Dung, sex:Male, Birth_Country:UK and other but when I push search it gives back a window with irrelevant with the search data. Can someone help me with that?</p>
  
  <p>The code I made for the search button after changes is:</p>
  
  <pre><code>public MySqlDataAdapter da;
  public DataSet ds;
  public string sTable = "data";
  
  private void anazitisi_button_Click(object sender, EventArgs e)
          {
              Form2 form2 = new Form2();
              try
              {
                  conn = openconnectio.GetConn();
  
                  string radiob = null;                               
                  if (radioButton1.Checked == true)
                  {
                      radiob = radioButton1.Text;
                  }
                  else if(radioButton2.Checked == true)
                  {
                      radiob = radioButton2.Text;
                  }
  
                  StringBuilder Query = new StringBuilder("SELECT * FROM data d INNER JOIN country c ON d.id_data = c.id_country WHERE 1=1 ");
                  if (!String.IsNullOrEmpty(textBox1.Text))
                      Query.Append(" AND name like '" + textBox1.Text + "'");
                  if (!String.IsNullOrEmpty(textBox2.Text))
                      Query.Append(" AND lastname like '" + textBox2.Text + "'");
                  if (!String.IsNullOrEmpty(radiob))
                      Query.Append(" AND sex like '" + radiob + "'");
                  if (!String.IsNullOrEmpty(maskedTextBox1.Text))
                      Query.Append(" AND birthdate like '" + maskedTextBox1.Text + "'");
                  if (!String.IsNullOrEmpty(maskedTextBox2.Text))
                      Query.Append(" AND phone_number like '" + maskedTextBox2.Text + "'");
  
                  MySqlDataAdapter da = new MySqlDataAdapter(Query.ToString(), conn);
                  ds = new DataSet();
                  da.Fill(ds, sTable);
                  conn.Close();
              }
              catch (MySql.Data.MySqlClient.MySqlException ex)
              {
                  MessageBox.Show(ex.Message);
  
              }
              finally
              {
                  DataGridView dg1 = new DataGridView();
                  form2.Controls.Add(dg1);
                  dg1.Dock = DockStyle.Fill;
  
                  dg1.Refresh();
                  dg1.DataSource = ds;
                  dg1.DataMember = sTable;
  
                  form2.Show();
  
                  if (conn != null)
                  {
                      conn.Close();
                  }
              }
          }
  </code></pre>
  
  <p>My results after search is fine when i comment that code:<br>
  (birthdate code) and i dont used as search of course.</p>
  
  <pre><code>        //if (!String.IsNullOrEmpty(maskedTextBox1.Text))
          //    Query.Append(" AND birthdate like '" + maskedTextBox1.Text + "'");
  </code></pre>
  
  <p>But when i use the (birthdate code) i get us result only a blank row.<br>
  <strong>I think</strong> because the birthdate maskedTextbox have a mask: 00/00/0000<br>
  Any suggestion?<br>
  Thanks.</p>