Private Sub SearchRecords() 'Call this when the search button is clicked
Dim strFilter As String = cboFilter.SelectedItem.ToSTring
Dim strKeyword As String = txtSearch.Text
Dim strLogic As String = ""
Dim strLogic2 As String = ""
Dim strRowFilter As String = ""
Select Case strFilter
Case "Exactly Match"
strLogic = "='"
strLogic2 = "'"
Case "Similar Match"
strLogic = "LIKE '%"
strLogic2 = "%'"
Case "Starts with"
strLogic = "LIKE '"
strLogic2 = "%'"
Case "Ends with"
strLogic = "LIKE '%"
strLogic2 = "'"
End Select
'Put the columns you wish to search for in this logic
'In my case, I'm searching for firstname, lastname and city
strRowFilter = "FirstName " & strLogic & strKeyword & strLogic2 & _
"OR LastName " & strLogic & strKeyword & strLogic2 & _
"OR City " & strLogic & strKeyword & strLogic2
dt.DefaultView.RowFilter = strRowFilter
If dt.DefaultView.Count > 0 Then
'found records
dgMain.DataSource = dt.DefaultView
Else
'no record so show all
dt.DefaultView.RowFilter = ""
dgMain.DataSource = dt
End If
End Sub