seach in database





1.00/5 (8 votes)
Dec 29, 2005

31707

264
search Using textbox
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+"%"
ContactIf 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.