how to search a database with a stored procedure?

W

wilco

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!!
 
J

Jerry III

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
 
X

Xavier MT

Can I ask what is the difference?

I just want to understand it....

Jerry III said:
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 said:
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


want's
to
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top