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?
Visual Basic.NETWindows OSSQL

Avatar of undefined
Last Comment
SchoolTeacher54

8/22/2022 - Mon
Éric Moreau

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

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
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SchoolTeacher54

ASKER

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!

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23