?
Solved

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

Posted on 2011-09-25
8
Medium Priority
?
538 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

771 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