title: How to populate gridview on button_click after searching from access database?
body: <p>I am creating a form in c#.net . I want to populate the <code>gridview</code> only on button click with entries meeting search criteria.</p>
  
  <p>I have tried but on searching ID it works but on searching FirstName it gives error plz check SQL also.</p>
  
  <p>Code behind:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
   {
              try
              {
                  string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=L:/New project/Project/Project/Data.accdb";
  
                  string sql = "SELECT * FROM AddressBook WHERE FirstName='" + textBox1.Text.ToString();
                  OleDbConnection connection = new OleDbConnection(strConn);
                  OleDbDataAdapter dataadapter = new OleDbDataAdapter(sql, connection);
                  DataSet ds = new DataSet();
                  connection.Open();
                  dataadapter.Fill(ds, "AddressBook");
                  connection.Close();
                  dataGridView1.DataSource = ds;
  
                  dataGridView1.DataMember = "AddressBook";
              }
              catch (System.Exception err)
              {
                  this.label27.Visible = true;
                  this.label27.Text = err.Message.ToString();
              }
     }
  </code></pre>