View Single Post
Old 02-02-2011, 05:55 PM   #1
Ciombe
 
Join Date: Feb 2011
Posts: 4
Default SQL Query using LIKE

Hi,
id' like to create a little search engine on my site and i have using this code for the DB connection in my result page called results.asp.

I get the values by a search page which have field called "campotesto1" anche select field called "select1"

HTML Code:
<%
Dim rsRicerca__MMColParam
rsRicerca__MMColParam = "-1"
If (Request.Form("campotesto1") <> "") Then 
  rsRicerca__MMColParam = Request.Form("campotesto1")
End If
%>
<%
Dim rsRicerca__MMColParam1
rsRicerca__MMColParam1 = "1"
If (Request.Form("select1") <> "") Then 
  rsRicerca__MMColParam1 = Request.Form("select1")
End If
%>
<%
Dim rsRicerca
Dim rsRicerca_cmd
Dim rsRicerca_numRows

Set rsRicerca_cmd = Server.CreateObject ("ADODB.Command")
rsRicerca_cmd.ActiveConnection = MM_dbShoemakers_STRING
rsRicerca_cmd.CommandText = "SELECT * FROM table WHERE field LIKE '%" + Replace(?, "'", "''") + "%' AND select_field = ? ORDER BY name DESC" 
rsRicerca_cmd.Prepared = true
rsRicerca_cmd.Parameters.Append rsRicerca_cmd.CreateParameter("param1", 200, 1, 255, rsRicerca__MMColParam) ' adVarChar
rsRicerca_cmd.Parameters.Append rsRicerca_cmd.CreateParameter("param2", 5, 1, -1, rsRicerca__MMColParam1) ' adDouble

Set rsRicerca = rsRicerca_cmd.Execute
rsRicerca_numRows = 0
%>
i use DW CS5 and ASP.

This query doesn't work cause a obtain and error:

"syntax error (missed operator), in query expression 'ield LIKE '%" + Replace(-1, "'", "''") + "%' AND select_field = 1 ORDER BY name DESC"


Where i'm in wrong?
Ciombe is offline   Reply With Quote