title: Making Datagrid Searchable with MySQL database in C# WPF
body: <p>So i got my dataGrid working in C# WPF, it connects to my MySQL database and shows the first name and last name of people in the database. What I'm trying to do now is make a search button that searches for the last name entered in a text box and display only those in the datagrid. I know this code will be wrong but I just don't know how to do this. Thanks for the help</p>
  
  <p>This connects to the database to get first name last name and it WORKS fine</p>
  
  <pre><code>try
  {
      command = connc.CreateCommand();
      command.CommandText = "SELECT First_name, Last_name FROM studentinfo";
      MySqlDataReader reader = command.ExecuteReader();
      string result = string.Empty;
      while (reader.Read())
      {
          result += reader["First_name"].ToString() + " " + 
          reader["Last_name"].ToString() + " ";
      }
      read = result.Split(' ');
      reader.Close();
      int count = 0;
  
  
      mySqlDataAdapter = new MySqlDataAdapter("SELECT First_name, Last_name FROM 
      studentinfo", connc);
      DataSet DS = new DataSet();
      mySqlDataAdapter.Fill(DS);
      data.SetBinding(ItemsControl.ItemsSourceProperty, new Binding { Source = 
      DS.Tables[0] });
  
      MessageBox.Show("S");
  }
  catch (Exception ex)
  {
      MessageBox.Show("something went wrong: " + ex.ToString());
  }
  </code></pre>
  
  <p>Here im trying to use a textbox to make the datagrid searchable </p>
  
  <pre><code>    command = connc.CreateCommand();
      mySqlDataAdapter = new MySqlDataAdapter("SELECT Last_name FROM studentinfo 
      WHERE Last_name = @Last_name", connc);
      command.Parameters.AddWithValue("@Last_name", txtsearch.Text);
      DataSet DS = new DataSet();
      mySqlDataAdapter.Fill(DS);
      data.SetBinding(ItemsControl.ItemsSourceProperty, new Binding { Source = 
      DS.Tables[0] });
  
      MessageBox.Show("S");
  }
  catch (Exception ex)
  {
      MessageBox.Show("something went wrong: " + ex.ToString());
  }
  finally
  {
      connc.Close();
  }
  </code></pre>