Hi, a pleasant day to all.

I just wanna ask if it is possible to search any string or keyword inside my Access Database using the search in my VB.net application? Most of the tutorials only teach on how to search the table using an exact keyword or input.

Example: I want to search the name JOHN SMITH. To be able to search that name, I need to type the whole name because if I only type JOHN there is zero result. If I only type SMITH there is also no result.

What I want is if type any of the two, there is a result. Even if just type "OHN" or "SMI" the name would be still in the result and wont return a no record found.

Is this possible? Thank you in advance.

By the way here is my code:

Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
    If txtSearch.Text = "" Then
        Call notFound()
        Exit Sub
    Else
        AdminRecordBindingSource.Filter = "(Convert(OfficeOrigin, 'System.String') LIKE '" & txtSearch.Text & "')" &
        "OR (OfficeOrigin LIKE '" & txtSearch.Text & "') OR (Particulars LIKE '" & txtSearch.Text & "') OR (ReceivedBy LIKE '" & txtSearch.Text & "')
        OR (DateReceived LIKE '" & txtSearch.Text & "') OR (StartTime LIKE '" & txtSearch.Text & "') OR (ActionTaken LIKE '" & txtSearch.Text & "')
         OR (FinishTime LIKE '" & txtSearch.Text & "') OR (TotalTime LIKE '" & txtSearch.Text & "') OR (Remarks LIKE '" & txtSearch.Text & "')"

        If AdminRecordBindingSource.Count <> 0 Then
            With DataGridView1
                .DataSource = AdminRecordBindingSource
            End With

        Else
            MsgBox("No record found")
            AdminRecordBindingSource.Filter = Nothing
        End If
    End If
End Sub

Unfortunately I don’t know VB.net. However, the way I would do it in my language of choice is to split the search string by spaces into an array of words. According to a Google search, this should accomplish that for you. Then, I would loop through the array of individual words looking for each one in my database. (Or, looping through the array to build an SQL query to search for any of the words individually.) Good luck!

Can you give us the actual query in pseudo code with field names? I think we can figure it out by first eliminating the vb.NET syntax. I typically use a SQL management console to get the underlying query before I add in the gory code details.

Hi to all, I already solved this problem. Thanks!

i don't know if u find solution suggest me to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.