title: C# MYSQL - Search filtering a datagridview with a combobox and textbox
body: <p>Hi I'm trying to search filter a <code>datagridview</code> by using a <code>combobox</code> and <code>textbox</code>.</p>
  
  <p>I have successfully done so but it only works properly when I search for the ID column. Other columns just crash display the following message:</p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MariaDB server version for the right syntax to use
    near 'Name LIKE 'd%'' at line 1</p>
  </blockquote>
  
  <p>The <strong>d</strong> letter in that error message is just the letter I was trying to filter the search with.</p>
  
  <p>Could somebody please help me solve this issue?</p>
  
  <p>My code is below</p>
  
  <pre><code>string myConnection = "datasource=localhost;port=3306;username=root;password=;";
  MySqlConnection conDatabase = new MySqlConnection(myConnection);
  try
          {
              if (comboBoxSrchPatient.Text == "ID")
              {
                  MySqlCommand cmd = new MySqlCommand("select * from clinic_inventory_system.patient WHERE ID LIKE '" + txtSearchPatient.Text + "%'", conDatabase);
                  MySqlDataAdapter sda = new MySqlDataAdapter();
                  sda.SelectCommand = cmd;
  
                  DataTable dbdataset = new DataTable();
                  sda.Fill(dbdataset);
                  dataPatientGridView.DataSource = dbdataset;
              }
              else if (comboBoxSrchPatient.Text == "FIRST NAME")
              {
                  MySqlCommand cmd = new MySqlCommand("select * from clinic_inventory_system.patient WHERE First Name LIKE '" + txtSearchPatient.Text + "%'", conDatabase);
                  MySqlDataAdapter sda = new MySqlDataAdapter();
                  sda.SelectCommand = cmd;
  
                  DataTable dbdataset = new DataTable();
                  sda.Fill(dbdataset);
                  dataPatientGridView.DataSource = dbdataset;
              }
  
              else if (comboBoxSrchPatient.Text == "LAST NAME")
              {
                  MySqlCommand cmd = new MySqlCommand("select * from clinic_inventory_system.patient WHERE Last Name LIKE '" + txtSearchPatient.Text + "%'", conDatabase);
                  MySqlDataAdapter sda = new MySqlDataAdapter();
                  sda.SelectCommand = cmd;
  
                  DataTable dbdataset = new DataTable();
                  sda.Fill(dbdataset);
                  dataPatientGridView.DataSource = dbdataset;
              }
  
              else if (comboBoxSrchPatient.Text == "AGE")
              {
                  MySqlCommand cmd = new MySqlCommand("select * from clinic_inventory_system.patient WHERE Age LIKE '" + txtSearchPatient.Text + "%'", conDatabase);
                  MySqlDataAdapter sda = new MySqlDataAdapter();
                  sda.SelectCommand = cmd;
  
                  DataTable dbdataset = new DataTable();
                  sda.Fill(dbdataset);
                  dataPatientGridView.DataSource = dbdataset;
              }
  
              else if (comboBoxSrchPatient.Text == "CONTACT NUMBER")
              {
                  MySqlCommand cmd = new MySqlCommand("select * from clinic_inventory_system.patient WHERE Contact Number LIKE '" + txtSearchPatient.Text + "%'", conDatabase);
                  MySqlDataAdapter sda = new MySqlDataAdapter();
                  sda.SelectCommand = cmd;
  
                  DataTable dbdataset = new DataTable();
                  sda.Fill(dbdataset);
                  dataPatientGridView.DataSource = dbdataset;
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
  </code></pre>