views:

107

answers:

2

I'm working on a simple e-commerce website right now, nothing real just practicing

the problem that I'm having is how to make a simple search in the website?

i.e. if I want to search for the word "iphone" in the database of the website.

how can I do that? and how can I specify a column to search in it instead of searching the whole table?

I'm using visual web developer express 2008 and SQL server 2008

A: 

One option is to use full-text searching that is built-in in SQL server 2008. You can read more information about it on this Microsoft site.

In short, you specify what columns you want to use for your full-text search (e.g. a 'title' and a 'text' column), configure them as such in the database and then use a regular query to do a full-text search (see example here).

Another option is to use a framework like Lucene.NET for full-text searching, which is definately more work to setup, but gives better performance, especially if you have many many records to search.

Razzie
+1  A: 

I may be simplifying this but if you want to search a specified varchar column in a specified table then do this:

One. Create a new stored proc in SQL Server that takes an input param such as @IN_SearchValue Eg.

CREATE PROCEDURE SearchProc @IN_SearchParam varchar(200) AS BEGIN SELECT * FROM TableName t WHERE t.ColumnName LIKE '%' + @IN_SearchParam + '%' END

Two. Reference this in .Net. One possible option is use a SQlConnection object and a SqlCommand object set-up to use the above procedure. Plenty of examples already out there.

Three. Deliver your results to your user!

littlechris