Re: Get records beginning with certain letter
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 6 Jul 2006 07:27:45 -0400
James Jones wrote:
<%
SQL_Get_Videos = "Select * FROM videos WHERE Artist LIKE '" & ltr &
"%'" rs.Open SQL_Get_Videos , conn
Oh! Don't do this! You are leaving your database and website vulnerable to
hackers using SQL Injection
(http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23)
Use parameters, instead; preferably via a saved parameter query :
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/b3d322b882a604bd
or, use a Command object like this:
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/72e36562fee7804e
If you use this technique, your sql string should be:
SQL_Get_Videos = "Select * FROM videos " & _
"WHERE Artist LIKE ? & '%'"
IF rs.EOF ThenIt always helps to tell us the details. When you said "search for numbers" I
%>No videos by artist beginning with the letter <%=ltr%>
<%
Else
%>
how would i get it to search for it beginning with numbers?
ltr is defined by a querystring
if the user selects "0-9" then it should show any video beginning
with the numbers 0-9. But since ltr is defined by the querystring, i
cant get it to search for the string that i was given in previous
post.
assumed you were talking about a numeric field. It never hurts to show us a
few rows of sample data, along with a description of the names and datatypes
of the fields involved.
So it sounds as if you have a Text field, containing strings some of which
begin with numbers: 0Abc, 3edf, etc. Correct?
Well, with Jet, you can do this:
" ... WHERE Left(fieldname,1) IN ('0','1', ..., '9')"
(you need to fill in the ... with the rest of the numbers)
This will not perform very well because it will not be able to use an index
if you have created one on the field. But then again, no other search method
will anyways. You would be better off creating a separate numeric field to
hold just the first character of the text you wish to search, creating an
index on that field. You could use the ascii code for the character, or
simply use -1 for alpha characters, and 0-9 for numeric characters.
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- References:
- Get records beginning with certain letter
- From: James Jones
- Re: Get records beginning with certain letter
- From: Bob Barrows [MVP]
- Re: Get records beginning with certain letter
- From: James Jones
- Re: Get records beginning with certain letter
- From: James Jones
- Re: Get records beginning with certain letter
- From: Bob Barrows [MVP]
- Re: Get records beginning with certain letter
- From: James Jones
- Get records beginning with certain letter
- Prev by Date: Check a number of columns against multiple values
- Next by Date: Re: Accessing Remote FoxPro table
- Previous by thread: Re: Get records beginning with certain letter
- Next by thread: Re: Get records beginning with certain letter
- Index(es):
Relevant Pages
|