VB.NET Is there a solution to search a data with random character in the middle of string? RRS feed

  • Question

  • Hello,

    i use programming app was vb6.0 and i want to learn

    i  created search in my form

    Textbox1 and Button5

    Public conn As ADODB.Connection
    Public ds As New DataSet
    Public da As New OleDb.OleDbDataAdapter
    Public rs As ADODB.Recordset

    I already declare connection and dataset

    ds.Tables("Masterlist").DefaultView.RowFilter = "DWGCONCAT like '*" & StrSearch & "*'"

    When i use this filter nothing is problem.



    I want to search record with random character in the middle of textbox1


    i want to search (user define) : P0137*SH

    code will be:

    "DWGCONCAT like '*P0137*SH*'"

    but this code is error

    ERROR MSG : Error in Like operator: the string pattern '*P0137*SH*' is invalid.

    Is there a solution to search a data with random character in the middle of string?

    Saturday, August 25, 2018 3:03 AM

All replies

  • Hi,

    Please provide the string in TextBox1 so we can assist you.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, August 27, 2018 2:56 AM
  • Hi,

    You can not use wild card in the middle of the Like filter criteria. 

    A wildcard is allowed at the start and end of a pattern, or at the end of a pattern, or at the start of a pattern. For example:

    "ItemName LIKE '*product*'"

    "ItemName LIKE '*product'"

    "ItemName LIKE 'product*'"

    Wildcard characters are not allowed in the middle of a string. For example, 'te*xt' is not allowed.

    You can escape the middle * with [*] in the pattern '*P0137*SH* as  '*P0137[*]SH*. 

    Follow the below references:

    DataColumn.Expression Property
    DataView RowFillter like operatorDataView RowFilter Syntax
    Correct way to escape characters in a DataTable Filter Expression

    -Niranjan Kala

    Monday, August 27, 2018 4:54 AM
  • If a single ‘*’ is expected in the middle of the text, then try this filter: “DWGCONCAT like 'P0137*'" AND DWGCONCAT like '*SH'”. For more precise solution, seems that you have to do some loops, maybe with Regular Expressions.

    Monday, August 27, 2018 7:49 AM