Click here to Skip to main content
15,891,253 members
Articles / Web Development / ASP.NET
Article

simple search use multiple words in textbox

Rate me:
Please Sign up or sign in to vote.
1.50/5 (11 votes)
29 Dec 2005 45.2K   817   21   2
Using simple code for searching in database

Introduction

It's always difficult when you want search in database using multiple words. That means we have textbox like "google" and you Enter Some words in textbox then click "go" ,at that time you want to search all the words  in textbox. This is really simple code for searching all tables that use VB.NET code and SQL server.

Background

For who wants to search in the database must know about text split in vb. you can do it in two ways:

1. Declare Stored Procedure in SQL then set parameters in VB then split textbox with split function.

2. Declare function and SQL string without Stored Procedure then search in database with textbox and split function.

Using the code

Here blow I first declare array with two parameters then I split the textbox with "split" function. If you using Stored Procedure you can declare parameter such as "Name" the in the Stored procedure declare SQL command.

Here is the code:

//code behind of webform1.aspx
Dim objparameter As New SqlParameter("@Name", SqlDbType.NVarChar, 50)
Dim a(2) As String
Dim j As Integer
a = txtsearch.Text.Split("", 2)
objcommand.Parameters.Add(objparameter)
objparameter.Direction = ParameterDirection.Input
For j = 0 To a.GetUpperBound(0)
objparameter.Value = a(j)
Next
//here is stored Procedure code
CREATE PROCEDURE main 
@Name nvarchar(50)

AS
select tables from computer where .... like "%"+@Name+"%"

Contact

If you have any question, or any comments, please contact me: mailto:info@articles.ir


Points of Interest

You can build your own simple search engine.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
I am IT Engineering and I write web application for 3 years.I love writing web programming such as asp.net,php and java Script.I am know work on XML a new technology for web developer.

Comments and Discussions

 
Generalsearch engine Pin
bk4code30-May-07 3:35
bk4code30-May-07 3:35 
GeneralRe: search engine Pin
jdelito27-Jun-07 21:06
jdelito27-Jun-07 21:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.