473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

how to search a database with a stored procedure?

hello,

can any one tell me how to create a stored procedure that is beable to
search a table, or more table's and can make use of wildcards?
i just made somthing like this,:
SELECT * FROM tblUsers WHERE Adress LIKE '* Value from user how wants to
search the database *'
but I don't know where to place the @??? for the input
i also wants to make the user can select witch table and field he want's to
search.

thanks!!
Nov 17 '05 #1
2 1471
And when you do it like this someone will sumbit "%' GO DELETE tblUsers --"
in your input box and wipe out your table (if the database user has enough
privileges to do so).

A better solution is to use the command object, like this:

OleDbCommand cmd = new OleDbCommand();

cmd.CommandText = "SELECT * FROM [tblUsers] WHERE [Address] LIKE @address";
cmd.Parameters.Add("@address", "%" + txtAddress.Text + "%");

Jerry

"David Wier" <dw***@nospamASPNet101.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Dim sAddress as String
sAddress=txtAddress.text
SQL = "SELECT * FROM tblUsers WHERE Adress Like '%" & sAddress & "%'"

Put the % sign on the front and at the end, in order to search the entire
field

Check out this 2 Part Tutorial on Parameterized Queries:
http://aspnet101.com/aspnet101/tutorials.aspx?id=1

LIKE is covered in Part 2

David Wier
http://aspnet101.com
http://aspexpress.com
"wilco" <wi**********@hetnet.nl> wrote in message
news:bg**********@reader11.wxs.nl...
hello,

can any one tell me how to create a stored procedure that is beable to
search a table, or more table's and can make use of wildcards?
i just made somthing like this,:
SELECT * FROM tblUsers WHERE Adress LIKE '* Value from user how wants to
search the database *'
but I don't know where to place the @??? for the input
i also wants to make the user can select witch table and field he want's

to
search.

thanks!!


Nov 17 '05 #2
Can I ask what is the difference?

I just want to understand it....

"Jerry III" <je******@hotmail.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
And when you do it like this someone will sumbit "%' GO DELETE tblUsers --" in your input box and wipe out your table (if the database user has enough
privileges to do so).

A better solution is to use the command object, like this:

OleDbCommand cmd = new OleDbCommand();

cmd.CommandText = "SELECT * FROM [tblUsers] WHERE [Address] LIKE @address"; cmd.Parameters.Add("@address", "%" + txtAddress.Text + "%");

Jerry

"David Wier" <dw***@nospamASPNet101.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Dim sAddress as String
sAddress=txtAddress.text
SQL = "SELECT * FROM tblUsers WHERE Adress Like '%" & sAddress & "%'"

Put the % sign on the front and at the end, in order to search the entire field

Check out this 2 Part Tutorial on Parameterized Queries:
http://aspnet101.com/aspnet101/tutorials.aspx?id=1

LIKE is covered in Part 2

David Wier
http://aspnet101.com
http://aspexpress.com
"wilco" <wi**********@hetnet.nl> wrote in message
news:bg**********@reader11.wxs.nl...
hello,

can any one tell me how to create a stored procedure that is beable to
search a table, or more table's and can make use of wildcards?
i just made somthing like this,:
SELECT * FROM tblUsers WHERE Adress LIKE '* Value from user how wants to search the database *'
but I don't know where to place the @??? for the input
i also wants to make the user can select witch table and field he
want's to
search.

thanks!!



Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Adrian Parker | last post by:
I have a database of 200+ tables (two tables per school), each with 100 - 4000 records (one record per student). A contract I'm looking at wants to be able to do a search across all the tables,...
0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
2
by: M Wells | last post by:
Hi All, I'm wondering if anyone can tell me if it's possible to search for stored procedures by their contents? I tend to leave very descriptive notes in stored procedures and they're...
3
by: huzz | last post by:
I've a table filed holds keywords seperated by comma, and a web search form where a user can type one of multiple keywords in the search text field seperated by comma aswell. How do i create a sql...
4
by: Axel | last post by:
Is it possible to write a Stored Procedure that takes a string of search keywords as argument and returns the recordset? At the mo I am passing the WHERE String as argument. I got this...
1
by: Matthew Curiale | last post by:
I am trying to create a search page for a database that will display in a repeater, using a stored procedure. The page_load is fine, and calls/displays all rows from the db just fine. When I input...
4
by: red vertigo | last post by:
HI All, Can't quite get my head aorund this problem. My knowledge or more importantly my experience of using T-SQL is small and as a consequence my stored procedures are basic. My current...
1
by: rshivaraman | last post by:
Hi All : A couple of tables have been identified to be deleted. My job is to find if it is at all used. On searching the web, i found a proc to search for a string within all databases in a...
2
by: COHENMARVIN | last post by:
I found that I'm making an error in my 'case' statements, and now I want to go through a database full of many stored procedures to find that error in some of them and to fix it. Is there any way...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.