"LIKE" does not work in VB.NET queries

Giovanni Conte 66 Reputation points
2023-09-28T16:24:33.94+00:00

I would like to retrieve records matching only a part of a field in vb.net. The old "Like" doesn't work anymore. Thank you in advance.

Developer technologies | VB
0 comments No comments
{count} votes

Accepted answer
  1. Boris 80 Reputation points
    2023-09-28T16:50:38.7533333+00:00

    In VB.NET, you can use the Select method of a DataTable to retrieve records that match a part of a field. The Select method allows you to use the Like keyword in a similar way to SQL. Here is an example

    Dim dt As DataTable = GetYourDataTable() ' Replace with your DataTable

    Dim rows() As DataRow = dt.Select("YourColumnName Like '%" & yourValue & "%'")

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Giovanni Conte 66 Reputation points
    2023-11-09T18:32:36.1566667+00:00

    Two hours ago I came across the message sent by Boris and, absentmindedly, I wrote this code in a form with a BindingSource and a DataGridView:

    Dim dt As DataTable = DataSetName.Tablename

    Dim rows() As DataRow = dt.Select("FieldName Like '%" & TextBox1.Text & "%'")

    BindingSource1.DataSource = rows

    I don't know why this code didn't work before.

    Thanks to Boris

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.