Quantcast
Channel: Adobe Community : All Content - ASP VBScript Development (read only)
Viewing all articles
Browse latest Browse all 106

Search page query parameters

$
0
0

I have a search page set up with a list box and a text box, the list box allows the user to select the field that they wish to search, while the text box allows them to type the search word they need to find.

 

The problem is that the first parameter sent for the formed SQL query does not appear to work.

If I have this SQL without the first parameter then this returns a recordset but limits the functionality of the page, with the EmpId 'hardcoded' as the search field.

SELECT * FROM dbo.sv_Employee
WHERE EmpId LIKE %MMColParam2%
ORDER BY EmpId ASC

 

What I want to do is allow the user to select the search field from the list box.

SELECT * FROM dbo.sv_Employee
WHERE MMColParam1 LIKE %MMColParam2%
ORDER BY EmpId ASC

 

Name: MMColParam1

Type: Text

Value: Request.Form("txtselect")

Default value: EmpId

 

Name: MMColParam2

Type: Text

Value: Request.Form("txtsearch")

Default value: 1

 

Now even when I set default values to the Recordset dialog box and click Test No Data is returned.

Do I need to do anything with the formatting of MMColParam1?

 

I should add that this is purely using DW code.

<%
Dim rssearch__MMColParam1
rssearch__MMColParam1 = "EmpId"
If (Request.Form("txtselect")  <> "") Then
  rssearch__MMColParam1 = Request.Form("txtselect")
End If
%>
<%
Dim rssearch__MMColParam2
rssearch__MMColParam2 = "1"
If (Request.Form("txtsearch")        <> "") Then
  rssearch__MMColParam2 = Request.Form("txtsearch")      
End If
%>
<%
Dim rssearch
Dim rssearch_cmd
Dim rssearch_numRows

 

Set rssearch_cmd = Server.CreateObject ("ADODB.Command")
rssearch_cmd.ActiveConnection = MM_connr_STRING
rssearch_cmd.CommandText = "SELECT * FROM dbo.sv_Employee WHERE ? LIKE ? ORDER BY EmpId ASC"
rssearch_cmd.Prepared = true
rssearch_cmd.Parameters.Append rssearch_cmd.CreateParameter("param1", 200, 1, 255, rssearch__MMColParam1) ' adVarChar
rssearch_cmd.Parameters.Append rssearch_cmd.CreateParameter("param2", 200, 1, 255, "%" + rssearch__MMColParam2 + "%") ' adVarChar

 

Set rssearch = rssearch_cmd.Execute
rssearch_numRows = 0
%>

 

Any help will be appreciated!


Viewing all articles
Browse latest Browse all 106

Trending Articles