Asp classic ASP搜索和结果在单个页面中
我有一个经典的ASP页面,我希望显示搜索表单和相关结果 当用户第一次访问此页面时,我希望显示搜索表单和10个最新属性。如果用户决定使用搜索表单来检索更多相关属性,那么我希望将默认的10个最新属性替换为用户的分页搜索结果 到目前为止,我的代码是这样的Asp classic ASP搜索和结果在单个页面中,asp-classic,Asp Classic,我有一个经典的ASP页面,我希望显示搜索表单和相关结果 当用户第一次访问此页面时,我希望显示搜索表单和10个最新属性。如果用户决定使用搜索表单来检索更多相关属性,那么我希望将默认的10个最新属性替换为用户的分页搜索结果 到目前为止,我的代码是这样的 <head> <title>Search</title> </head> <body> <div class="search"> <h3>Search fo
<head>
<title>Search</title>
</head>
<body>
<div class="search">
<h3>Search form</h3>
<form id="form1" name="form1" method="post" action="gist188770.asp">
<label>Street: <input type="text" name="searchStreet" value="<%=Server.HtmlEncode(Request("searchStreet") & "") %>" /></label>
<label>Town: <input type="text" name="searchTown" value="<%=Server.HtmlEncode(Request("searchTown") & "") %>" /></label>
<input type="submit" name="Submit" value="Submit" />
</form>
</div>
<%
if (Request.ServerVariables("REQUEST_METHOD") = "POST") then
'arrived via post get form values and do search
Dim myRecordSet
Dim myRecordSet_numRows
Set myRecordSet = Server.CreateObject("ADODB.Recordset")
myRecordSet.ActiveConnection = MM_dbconn_STRING
'collect the form input
set objDBParam = objDBCommand.CreateParameter("@ContentStreet",200,1,100)
objDBCommand.Parameters.Append objDBParam
objDBCommand.Parameters("@ContentStreet") = Request.QueryString("searchStreet")
set objDBParam = Nothing
set objDBParam = objDBCommand.CreateParameter("@ContentStreet",200,1,100)
objDBCommand.Parameters.Append objDBParam
objDBCommand.Parameters("@ContentTown") = Request.QueryString("searchTown")
set objDBParam = Nothing
set objDBParam = objDBCommand.CreateParameter("@ContentStreet",200,1,20)
objDBCommand.Parameters.Append objDBParam
objDBCommand.Parameters("@ContentPostcode") = Request.QueryString("searchPostcode")
set objDBParam = Nothing
'check for a match
myRecordSet.Source = "SELECT *"
myRecordSet.Source = myRecordSet.Source& "FROM ("
myRecordSet.Source = myRecordSet.Source& "SELECT id"
myRecordSet.Source = myRecordSet.Source& "FROM ("
myRecordSet.Source = myRecordSet.Source& "SELECT id"
myRecordSet.Source = myRecordSet.Source& "FROM VWTenantPropertiesResults"
myRecordSet.Source = myRecordSet.Source& "WHERE ContentStreet LIKE '%" & "@ContentStreet" & "%'"
myRecordSet.Source = myRecordSet.Source& "UNION ALL"
myRecordSet.Source = myRecordSet.Source& "SELECT id"
myRecordSet.Source = myRecordSet.Source& "FROM VWTenantPropertiesResults"
myRecordSet.Source = myRecordSet.Source& "WHERE ContentTown LIKE '%" & "@ContentTown" & "%'"
myRecordSet.Source = myRecordSet.Source& "UNION ALL"
myRecordSet.Source = myRecordSet.Source& "SELECT id"
myRecordSet.Source = myRecordSet.Source& "FROM VWTenantPropertiesResults"
myRecordSet.Source = myRecordSet.Source& "WHERE ContentPostCode LIKE '%" & "@ContentPostcode" & "%'"
myRecordSet.Source = myRecordSet.Source& ") qi"
myRecordSet.Source = myRecordSet.Source& "GROUP BY"
myRecordSet.Source = myRecordSet.Source& "id"
myRecordSet.Source = myRecordSet.Source& "HAVING COUNT(*) >= 2"
myRecordSet.Source = myRecordSet.Source& ") q"
myRecordSet.Source = myRecordSet.Source& "JOIN VWTenantPropertiesResults r"
myRecordSet.Source = myRecordSet.Source& "ON r.id = q.id"
myRecordSet.Source = myRecordSet.Source& "WHERE ContentBedrooms BETWEEN 1 AND 4"
myRecordSet.Source = myRecordSet.Source& "AND ContentPrice BETWEEN 50 AND 500"
myRecordSet.Source = myRecordSet.Source& "ORDER BY"
myRecordSet.Source = myRecordSet.Source& "ContentPrice"
'display the results
if myRecordSet.BOF then
response.write("Latest properties:<br>")
do until myRecordSet.EOF
%>
<div class='result'>")
<dl><%=myRecordSet("ContentTitle")%></dl>
<dt><%=myRecordSet("ContentStreet")%></dt>
<dt><%=myRecordSet("ContentTown")%></dt>
<dt><%=myRecordSet("ContentPostcode")%></dt>
</div><%
myRecordSet.MoveNext
loop
end if
else
'arrived via get show last 10 results
Dim myRecordSet2
Dim myRecordSet2_numRows
Set myRecordSet2 = Server.CreateObject("ADODB.Recordset")
myRecordSet2.ActiveConnection = MM_dbconn_STRING
myRecordSet2.Source = "SELECT TOP 10 FROM VWTenantPropertiesResults ORDER BY ContentPrice"
'display the results
if myRecordSet2.BOF then
do until myRecordSet2.EOF
%>
<div class='result'>")
<dl><%=myRecordSet2("ContentTitle")%></dl>
<dt><%=myRecordSet2("ContentStreet")%></dt>
<dt><%=myRecordSet2("ContentTown")%></dt>
<dt><%=myRecordSet2("ContentPostcode")%></dt>
</div><%
myRecordSet2.MoveNext
loop
end if
end if
%>
</body>
</html>
第98行如下:
if myRecordSet2.BOF then
我想知道是否有人能帮我解决这个问题?谢谢你提供的任何帮助
Neil.您在使用
BOF
时尚未打开记录集
此外,您正在创建一个命令对象,但没有将SQL文本分配给它,而是将SQL文本直接分配给记录集
您应该将SQL分配给命令对象的CommandText
属性,然后通过调用命令对象Execute
方法检索记录集
编辑:
更多需要修理的东西
SQL表达式在每行末尾不包含任何vbCrLf
或空格。SQL将不会执行
不要将连接字符串直接分配给ActiveConnection
,因为这样做ADODB无法正确管理连接池。始终实例化连接
对象,并将其指定给活动连接
属性
编辑2:
还有一个问题
您的代码正在从
请求访问标准。QueryString
但是表单
元素指定了method=“post”
,在这种情况下,您应该使用请求。表单
。请将相关代码发布到您的问题中,而不是链接到外部资源。
if myRecordSet2.BOF then