Link to home
Start Free TrialLog in
Avatar of SchoolTeacher54
SchoolTeacher54

asked on

VB.net BindingSource Filter string

I have a vb.net windows form that uses filters on the on [bindingsource]
I am trying to get a search criteria that is found anywhere in a string to return in the filter results.
[exisiting code] Master_ContactsBindingSource.Filter = "c_company = '" & InStr(CompanySearch.Text, 1) & "'"

The problem is that I receive no results (and does not error either) for terms that I know are in the table such as "son".

The desired result is to return all records that contain the search term "son" but clearly I have this wrong.

c_company = [table field]
[CompanySearch.text] is the textbox with the search term

Thoughts?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

as per the documentation (https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.strings.instr?view=netframework-4.8), your arguments seems to be in an incorrect order. I think it should be:
Master_ContactsBindingSource.Filter = "c_company = '" & InStr(1, CompanySearch.Text) & "'"

Open in new window

Avatar of SchoolTeacher54
SchoolTeacher54

ASKER

Eric,


I 'think' I had that sequence somewhere along the way of experimenting. I corrected the string to read as you indicated (I agree with it) however I still receive no results for something such as 'b'. To sort this out I've included some strings that DO work in other areas of the program for reference. I know the field and string captures correctly. The hangup is when I get to the Instr (issue).


Master_ContactsBindingSource.Filter = "c_company like '" & CompanySearch.Text & "*'"
Master_ContactsBindingSource.Filter = "c_address <>''  And  c_company Like '" & CompanySearch.Text & "*'"


I appreciate your help!

Scott

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I found that the following works perfect. Boy was I climbing the wrong side of the tree!


Master_ContactsBindingSource.Filter = "c_company like '%" & CompanySearch.Text & "%'"


I get any occurrence of a string which was the goal.


Thank you for the poke Eric!