title: VB SQL ACCESS Select Where Like Statement
body: <p>Net, i'm trying to learn how to display a query result into data grid whenever i click the Search Button as a trigger event for the query. 
  But nothing happens when i click the Search Button but gives me an error message (Please see link for the screenshot of error message) which i don't understand. </p>
  
  <p>Error: <a href="http://s1.postimg.org/di091riv3/error1.jpg" rel="nofollow">http://s1.postimg.org/di091riv3/error1.jpg</a></p>
  
  <p>Can you please point me to the right track, Thanks.</p>
  
  <p>Here is my code below</p>
  
  <pre><code>Imports System.Data.OleDb
  
  Public Class SearchForm
      Dim con As New OleDbConnection
  
  
  
      Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Statd.SelectedIndexChanged
  
      End Sub
  
  
      Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
  
          con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= c:\Databse\Company_db.accdb"
          con.Open()
  
  
          Dim sqlQuery As String
          Dim sqlCommand As New OleDbCommand
          Dim sqlAdapter As New OleDbDataAdapter
          Dim Table As New DataTable
          Dim empNum As String
          Dim empLname As String
          Dim empDept As String
          Dim empStat As String
  
  
          empNum = eNumText.Text
          empLname = empLnameText.Text
          empDept = Deptd.Text
          empStat = Statd.Text
  
          sqlQuery = "SELECT * FROM tbl_empinfo WHERE LastName like '% " &amp; empLnameText.Text &amp; "' "
  
          ' MsgBox("Employee Number " + empNum + empLname + empDept + empStat) 'test statement 
  
  
          With sqlCommand
              .CommandText = sqlQuery
              .Connection = con
  
              With sqlAdapter
                  .SelectCommand = sqlCommand
                  .Fill(Table)
  
              End With
  
              For i = 0 To Table.Rows.Count - 1
                  With DataGridView1
                      .Rows.Add(Table.Rows(i)("EmpID"), Table.Rows(i)("FirstName"), Table.Rows(i)("LastName"), Table.Rows(i)("Department"), Table.Rows(i)("Position"), Table.Rows(i)("Status"), Table.Rows(i)("Years"))
  
                  End With
              Next
  
  
          End With
  
  
  
  
  
  
          con.Close()
      End Sub
  </code></pre>