Solved

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

Posted on 2011-09-25
8
505 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
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
 

Author Comment

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

0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now