Click here to Skip to main content
Click here to Skip to main content

simple search use multiple words in textbox

, 29 Dec 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

hamidreza Talebi
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 Pinmemberbk4code30-May-07 3:35 
GeneralRe: search engine Pinmemberjdelito27-Jun-07 21:06 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 29 Dec 2005
Article Copyright 2005 by hamidreza Talebi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid