Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Using the like command in SQL

Reply
Thread Tools

Using the like command in SQL

 
 
MasterChief
Guest
Posts: n/a
 
      11-03-2005
I have a form that uses the POST method to call up test.asp and it
passes what is typed into the text box. Since is uses the Like command
the user can enter stuff like %Constant% to get something that is like
what the user typed in. When I call up the test.asp page it is grabbing
the text fine but isn't running the SQL command the correct way. The
SQL command ends up being

SELECT * FROM [Everyone] WHERE (Name LIKE ':: & strName & ::')

Here is my code


strName = Request.Form("Search")
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
Conn.Open "PhoneList"
sSQL = "SELECT * FROM [Everyone] WHERE (Name LIKE ':: & strName & ::')"
Set Rs = Conn.Execute(sSQL)

 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      11-03-2005
MasterChief wrote:
> I have a form that uses the POST method to call up test.asp and it
> passes what is typed into the text box. Since is uses the Like command
> the user can enter stuff like %Constant% to get something that is like
> what the user typed in. When I call up the test.asp page it is
> grabbing the text fine but isn't running the SQL command the correct


What database are you using?

> way. The SQL command ends up being
>
> SELECT * FROM [Everyone] WHERE (Name LIKE ':: & strName & ::')


Is it Access?
http://www.aspfaq.com/show.asp?id=2096

>
> Here is my code
>
>
> strName = Request.Form("Search")
> Set Conn = Server.CreateObject("ADODB.Connection")
> Set Rs = Server.CreateObject("ADODB.RecordSet")
> Conn.Open "PhoneList"
> sSQL = "SELECT * FROM [Everyone] WHERE (Name LIKE ':: & strName &
> ::')"


What is the reason for the double-colons? They should not be there. Also,
you need to concatenate the _value_ of the variable into your string, not
the name of the variable.

sSQL = "SELECT * FROM [Everyone] WHERE Name LIKE '" & _
strName & "'"

You should know that you are leaving your site and database vulnerable to
hackers using sql injection:
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23
http://www.nextgenss.com/papers/adva..._injection.pdf

You should not be using dynamic sql, and you should not be allowing users to
control your sql statement by what they type in your form. You should
provide a checkbox on your form to allow users to specify whether or not a
wildcard search is to be performed. Then, depending on the value of the
checkbox, use the appropriate sql statement:

if wildcard_on then
sSQL = "SELECT * FROM [Everyone] WHERE Name LIKE '%" & _
strName & "%'"
else
sSQL = "SELECT * FROM [Everyone] WHERE Name ='" & _
strName & "'"
end if

Here are some links about using parameters:
http://groups.google.com/groups?hl=e...tngp13.phx.gbl

http://groups.google.com/groups?hl=e...TNGP11.phx.gbl

http://www.google.com/groups?selm=eE...&output=gplain

http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

Using Command object:
http://groups-beta.google.com/group/...e36562fee7804e

SQL Server
http://tinyurl.com/jyy0

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
 
 
 
MasterChief
Guest
Posts: n/a
 
      11-04-2005
This is an Access Database. I am not to worried about SQL injections.
This is actually an intranet site for a lumber company. I know almost
every employee here and they have a hard enough time with the basic
stuff. But yes I do understand your point about using this in a real
world scenario. I will try your suggestion in a while. I put the ::
because original the search page was one page and I used a tutorial
online that worked and they had me use the :: so I thought it was
something that had to be used.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to enumerate a list of sql servers (isql -L like command) in Java! Remi Morin Java 0 10-23-2006 04:15 PM
object-like macro used like function-like macro Patrick Kowalzick C++ 5 03-14-2006 03:30 PM
Using the like command in SQL MasterChief ASP General 0 11-03-2005 08:13 PM
SQLConnection SQL Command SQL DataAdapter Biggie ASP .Net 1 02-06-2004 04:32 AM
distutil: how do a post-install command like create a soft link? ..or where add command to setup.py?? Christian Seberino Python 0 10-21-2003 10:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57