title: Vb.net, how to use filter with LIKE clause when the filter text contains %?
body: <p>I want to filter a text in all columns in a datagridview. So I use Like % in the filter text. However, I found that the text(strFilter in my code) may contain % sometimes. So it have a syntax error. How can I use filter with like clause when the filter text contains %? </p>
  
  <pre><code>    Private Sub PassFilter(ByRef dataTable As DataTable, ByVal strFilter As String)
      Try
          Dim dataview As DataView = dataTable.DefaultView
          Dim strExp As String = ""
          For Each col As DataColumn In dataTable.Columns
              If Not String.IsNullOrEmpty(strFilter) Then
                  If strExp = "" Then
                      strExp += "[" &amp; col.ColumnName &amp; "]" &amp; " LIKE '%" &amp; strFilter &amp; "%'"
                  Else
                      strExp += " OR " &amp; "[" &amp; col.ColumnName &amp; "]" &amp; " LIKE '%" &amp; strFilter &amp; "%'"
                  End If
              End If
          Next
  
          dataview.RowFilter = strExp
  
      Catch ex As Exception
          ShowMessage("Unable to filter datagridview." + ex.Message)
      End Try
  
  
  End Sub
  </code></pre>