Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All

I want to include the search box in my website which will find the contents of my website locally. Please guide me how to add search functionality in my website.




Regards

Amy
Posted
Updated 29-Jul-15 10:04am
v2
Comments
F-ES Sitecore 29-Jul-15 15:35pm    
What do you mean by "locally"?
[no name] 29-Jul-15 15:36pm    
http://www.bing.com/search?q=asp.net+add+search+to+website try to do some basic research yourself.
AmyAli 29-Jul-15 16:02pm    
I mean (locally) internal contents of website
[no name] 29-Jul-15 16:06pm    
So what?

1 solution

Search in database is just a simple SQL query with LIKE clause to find a relative record. Although it just needs a simple input control (input element), and a page where you will handle the user input, the query and then generate results as per the query and database records.

For example, this article of mine, How to search for related query inside the Database using ASP.NET[^], covers the topic that you are finding. It simply uses a single input element, and upon submission it looks for records in the database that might have the query in it.

A sample would be,
SQL
SELECT * FROM table_name WHERE column_name LIKE %parameter%


Always use parameters to prevent SQL Injections, above code would look for records that match (I have used %% that would search for any word, starting with, ending with or containing the keyword) your keyword, parameterized keyword. You can execute it in many ways, using ASP.NET Web Helpers' Database object or you can use SqlClient to connect to database.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900