说声明麻烦

时间:2010-01-08 19:13:07

标签: sql visual-studio-2008 sql-like tableadapter

我在VB 2008中使用TableAdapter和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 & "%"

请帮助!

2 个答案:

答案 0 :(得分:1)

你的Where子句应该是

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

如果要在LastName字段中的任何位置搜索searchValue。

答案 1 :(得分:0)

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

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