views:

52

answers:

2

I am having some issues while using the TableAdapter and the LIKE Statement in VB 2008. I am wanting to search name using partial spellings. When I run the application nothing is returned.

Here is my SQL:

SELECT        MEMBERS.RolodexID, MEMBERS.FirstName, MEMBERS.LastName, MEMBERS.address, MEMBERS.Address2, MEMBERS.City, MEMBERS.State, 
                         MEMBERS.Zip, MEMBERS.AreaCode1, MEMBERS.LocalNumber1, MEMBERS.AreaCode2, MEMBERS.LocalNumber2, MEMBERS.AreaCode3, 
                         MEMBERS.LocalNumber3, Member_Employers.Department, Member_Employers.Job_Class, EMPLOYER.NAME, MEMBERS.Industry, 
                         EMPLOYER.CODE
FROM            EMPLOYER INNER JOIN
                         Member_Employers ON EMPLOYER.CODE = Member_Employers.Employer_Code INNER JOIN
                         MEMBERS AS MEMBERS ON Member_Employers.Rolodexid = MEMBERS.RolodexID
WHERE        (MEMBERS.LastName like ?)

Here is my VB code:

DIM LastName as String

LastName = me.txt_LastName.text

Me.MEMBERSTableAdapter.FillBy(DataSet1.MEMBERS, LastName)

I've tried a couple of other codes including:

LastName = "'" & me.txt_LastName.text & "%'"

or

LastName = me.txt_LastName.text & "%"

Please Help!

+1  A: 

Your Where clause should be

WHERE        (MEMBERS.LastName like '%searchValue%') 

if you want to search for searchValue anywhere within the LastName field.

rosscj2533
I don't think this will work, parameterized queries put in quotes for you. So you end up with something like `'%'sam'%'`
Hogan
A: 

LastName = "%"+me.txt_LastName.text+"%" is what you want.

Note the lack of single quotes. I know it is silly, but it is how it works.

Hogan