Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need SQL query in VB.NET that search in column to Multiple Keywords

Posted on 2011-09-25
8
Medium Priority
?
550 Views
Last Modified: 2012-06-27
Hello,

I've a table with 3 fields

ProdictID - ProductDescription - Price

Now I want to build a dynamic seach option. I've a textbox to enter the keywords in.

Now when i click on my search button I should get the result of the keywords I've entered.

Could somebody help me with this?

Thanks
0
Comment
Question by:prinsbj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:Eyal
ID: 36594925
select * from products where ProductDescription like '%'+SearchText+'%'
0
 

Author Comment

by:prinsbj
ID: 36594951
That's right but when i put in multiple keywords the it looks to:

Sample: Keyword_1 Keyword_2 Keyword_3

In your code it will look to "Keyword_1 Keyword_2 Keyword_3"

I've to look to the keywords separete. "Keyword_1" And "Keyword_2" And "Keyword_3"

Or if I put in 2 keywords than for 2.

Hope you know what I mean?

Thanks

0
 
LVL 15

Expert Comment

by:Eyal
ID: 36594955
Now I understood what is your problem.

can it be exact search or it must include %%?
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:prinsbj
ID: 36594962
It must incl %%.

0
 
LVL 15

Expert Comment

by:Eyal
ID: 36594980
you can do it in 3 ways

1) execute_sql (@str) where @str is a query you build (I don't like this solution)
2) use data base cursor
3) use linq in the program :

List<string> uids = new List<string>( arrayofields.split(' ') );

from xx in table
where uids.Contains( xx.ToString() )
select xx
0
 

Author Comment

by:prinsbj
ID: 36595040
Could you explain met optie 3 more. I've use dataset in visual studio.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 36595271
You also should look into Full-Text Search, especially if the table is large.  Once Full-Text Search is setup and the index populated your query becomes as simple as:
SELECT *
FROM YourTableName
WHERE CONTAINS(YourColumn, '"Keyword1 OR Keyword2 OR Keyword3 OR ..."')
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36595449
Try using a query like
(Untested)

Dim Query As String = "Select * from tblProducts Where ProductDescription"
If txtSearch.Text.Contains(" ") Then
 Dim Words As String() = txtSearch.Text.Split(" ")
 For Each Word in Words
     Query &= " Like '%" & word & "%' OR ProductDescription"
 Next
 Query = Query.TrimEnd("OR ProductDescription".ToCharArray())
Else
 Query &= "Like '%" & txtSearch.Text & "%'"
End If

'Execute query
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question