問題描述
我正在嘗試在我的網站上創建一個搜索文本框,而不是在提交時將字符串關鍵字"傳遞到我的網格中并提取該關鍵字的所有匹配記錄.
I'm trying to create a search text-box on my website than when submitted will pass the 'string-keyword' into my grid and pull all matching records for that keyword.
我必須使用 where 語句設置我的網格,該語句將偵聽"表單通過查詢字符串傳入的參數.
I'm having to setup my grid with a where statement that will "listen" for parameters passed in by the form via query-string.
我不知道如何解決這個問題.任何見解、提示、示例表示贊賞.
I'm not sure how to approach this. Any insight, tips, examples appreciated.
更新-------這是我的網格用于填充記錄的查詢.除了城市/地區/國家之外,我還嘗試合并一個關鍵字搜索,它只會查看 BND_Listing 表中的公司"字段.
UPDATE------- This is the query my grid is using to populate records. In addition to City/Region/Country I'm trying to incorporate a keyword Search that would only look at my 'Company' Field inside the BND_Listing table.
select * FROM BND_listing right join BND_ListingCategories
on BND_Listing.CatID=BND_ListingCategories.CatID
where
(CategoryName = '[querystring:filter-Category]' or '[querystring:filter- Category]'='All')
and
(City = '[querystring:filter-City]' or '[querystring:filter-City]'='All')
and
(Region= '[querystring:filter-State]' or '[querystring:filter-State]'='All')
and
(Country= '[querystring:filter-Country]' or '[querystring:filter- Country]'='All')
and
isnull(Company,'') <> ''
ORDER by Company ASC
推薦答案
我不知道你說的監聽"參數是什么意思,但因為你只有 TSQL
標記,匹配部分在 SQL Server 中是這樣實現的:
I don't know what you mean by "listen" for parameters, but since you only have TSQL
tagged, the matching part in SQL Server is achieved like so:
DECLARE @param VARCHAR(256) --or what ever size you need
SET @param = 'some text'
SELECT SomeColumns
FROM SomeTable
WHERE aColumn LIKE '%' + @param + '%'
或者在 VB 中使用 SqlCommand
你可以查看:https://stackoverflow.com/a/251311/6167855
Or using SqlCommand
in VB you can check out: https://stackoverflow.com/a/251311/6167855
這篇關于用于搜索“關鍵字"的表字段的 T-SQL 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!