title: c# Listview Search using Textbox
body: <p>I Have a c# windows form that can save <code>ID, Name,</code>and<code>Birthday</code> into my <code>Employee</code> Table. I use these codes to save data in my table Using <code>Save Button</code>:</p>
  
  <pre><code>private void Save_Click_1(object sender, EventArgs e)
      {
          try
          {
              MainDatabaseDataSetTableAdapters.EmployeeTableAdapter employee = new MainDatabaseDataSetTableAdapters.EmployeeTableAdapter();
              employee.InsertQuery(textBox1.Text.Trim(),
                  textBox2.Text.Trim(),
                  textBox3.Text.Trim());
  
  
              MessageBox.Show("Saved");
  
          }
  
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }
  </code></pre>
  
  <p>with this Query:</p>
  
  <blockquote>
    <p>INSERT INTO Employee
                             (ID, Name, Birthday) VALUES        (@ID,@Name,@Birthday)</p>
  </blockquote>
  
  <p>I Use <code>Populate Button</code> to show my saved data from my Database into <code>Listview</code> using this code:</p>
  
  <pre><code>private void Populate_Click(object sender, EventArgs e)
      {
          listView1.Items.Clear();
  
          DataTable dtable = mainDatabaseDataSet.Tables["Employee"];
  
          for (int i = 0; i &lt; dtable.Rows.Count; i++)
          {
              DataRow drow = dtable.Rows[i];
  
              if (drow.RowState != DataRowState.Deleted)
              {
                  ListViewItem item = new ListViewItem(drow["ID"].ToString());
                  item.SubItems.Add(drow["Name"].ToString());
                  item.SubItems.Add(drow["Birthday"].ToString());
  
                  listView1.Items.Add(item);
              }
          }
  </code></pre>
  
  <p>So my Problem now is that I don't have any Idea on how to put a search in my <code>listview</code> using a <code>textbox</code> and <code>SearchButton</code>.</p>
  
  <p>I have a <code>SearchQuery</code>: </p>
  
  <blockquote>
    <p>SELECT        ID, Name, Birthday FROM            Employee WHERE<br>
    (Name = @Name)</p>
  </blockquote>
  
  <p>and I thought I can insert this in my <code>SearchButton</code> but I don't know how.</p>
  
  <p>Please somebody Help.</p>
  
  <p>Before I used this code to Populate my listview </p>
  
  <pre><code> DataTable dtable = mainDatabaseDataSet.Tables["Employee"];
  </code></pre>
  
  <p>I used this codes to Search and it worked. I set my DB Connection Using this Code:</p>
  
  <pre><code> public SqlCeConnection connection = new SqlCeConnection(@"Data Source = C:\...\...\...");
  </code></pre>
  
  <p>Then I inserted this codes in my <code>SearchButton</code>:</p>
  
  <pre><code> private void button2_Click(object sender, EventArgs e)
      {
  
  
          SqlCeCommand search = new SqlCeCommand("SELECT * FROM Employee Where Name like '%" + Search.Text + "%'", connection);
  
  
          try
          {
              SqlDataReader datareader = search.ExecuteReader();
  
  
              while (datareader.Read())
              {
                  ListViewItem item = new ListViewItem(datareader["ID"].ToString());
                  item.SubItems.Add(datareader["Name"].ToString());
                  item.SubItems.Add(datareader["Birthday"].ToString());
  
  
                  listView1.Items.Add(item);
              }
          }
  
  
          catch (SqlException ex)
          {
              MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
      }
  </code></pre>
  
  <p>but this is not what my teacher wants. He wanted to see how I do the search using this code to populate the Listview </p>
  
  <pre><code>DataTable dtable = mainDatabaseDataSet.Tables["Employee"];
  </code></pre>
  
  <p>I know someone here could have an Idea on how to do this. Please help me.</p>