2010-01-08 103 views
0

我在使用VB 2008中的TableAdapter和LIKE语句时遇到了一些问题。我想使用部分拼写搜索名称。当我运行应用程序时,什么都没有返回。LIKE语句问题

这里是我的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 ?) 

这里是我的VB代码:

DIM LastName as String 

LastName = me.txt_LastName.text 

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

我试过几个其他的代码包括:

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

LastName = me.txt_LastName.text & "%" 

请帮忙!

回答

1

你Where子句应该是

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

,如果你想姓氏字段中的任何地方搜索searchValue。

+0

我不认为这会起作用,参数化查询会为你引用引号。所以你最终得到了'''''sam'%'' – Hogan 2010-01-08 20:30:34

0

LastName = "%"+me.txt_LastName.text+"%"是你想要的。

请注意缺少单引号。我知道这很愚蠢,但它是如何运作的。