在Visual Basic和SQL查询生成器中使用LIKE运算符 [英] using LIKE operator within visual basic and sql query builder
问题描述
您好,我有一个带有数据网格和图片框的可视化基本Windows窗体.
datagrid连接到包含三个字段的数据库:
Hi there, I have a visual basic windows form with a datagrid and a picturebox.
The datagrid is hooked up to a database that contains three fields :
Id int
Description varchar(100)
AbsPath varchar(200)
表单加载时,图片框将填充AbsPath中的照片图像.
就其本身而言,没什么特别的.
我已经配置了一个查询来搜索像这样的描述:
when the form loads the picturebox is filled with a photo image from AbsPath.
Nothing special about that in its self.
I have configured a query to search description like this:
SELECT id, Description, AbsPath
FROM TablePhoto
WHERE (Description LIKE @Description + N'%')
问题是搜索仅匹配说明"左侧的匹配项
因此,如果我输入"white"进行搜索,我会得到
白玫瑰
白花
等
如果输入花",我什么也没得到
根据我阅读的内容,我应该能够使用LIKE通配符%%,这样搜索将匹配描述中的花",因此我应该得到:
The problem is the search only matches from the left of ''description"
So if I enter "white" for the search I get
white rose
white flower
etc
If I enter "flower" I get nothing
According to what I have read I should be able to use the LIKE wildcard %% so the search will match "flower" within the description so I should get:
white flower<br />
Blue flower<br />
etc
但是要使用的正确语法是什么,我尝试了各种组合,但是查询生成器dosnt似乎很喜欢.
在此先感谢您的帮助
But what is the correct syntax to use, I have tried various combinations but the query builder dosnt seem to like it.
Thanks in advance for any help
推荐答案
SELECT id, Description, AbsPath
FROM TablePhoto
WHERE (Description LIKE '%'+@Description+'%')
从TablePhoto中选择id,描述,AbsPath,其中描述类似于''%''+ @Description +''%''
试试这个
问候,
Anilkumar.D
select id, Description, AbsPath from TablePhotowhere Description LIKE ''%'' + @Description+''%''
try this
Regards,
Anilkumar.D
这篇关于在Visual Basic和SQL查询生成器中使用LIKE运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!