LIKE 语句麻烦
我在 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 & "%"
请帮忙!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
则应使用Where 子句。
如果您想在 LastName 字段中的任何位置搜索 searchValue,
Your Where clause should be
if you want to search for searchValue anywhere within the LastName field.
LastName = "%"+me.txt_LastName.text+"%"
就是你想要的。请注意缺少单引号。我知道这很愚蠢,但这就是它的运作方式。
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.