Solved

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

Posted on 2011-09-25
8
520 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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 500 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

738 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