请大家帮帮忙,ASP实现智能搜索,有一个小问题
请大家帮帮忙,ASP实现智能搜索,有一个小问题
楼主chshhxyz012()2006-07-12 09:45:54 在 Web 开发 / ASP 提问 源码:
<%
Dim strProvider,CNN
strProvider="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strProvider=strProvider & Server.MapPath("data\yinglou.mdb") "假设数据库存放在主页根目录下的data目录下
Set CNN = Server.CreateObject("ADODB.connection")
CNN.Open strProvider "打开数据库连接 %>
<%
Dim S_Key,RST,StrSQL
S_Key = Trim(Request("key")) "得到搜索关键字的值
If S_Key <>"" then
Set RST=Server.CreateObject("ADODB.RecordSet")
StrSQL=AutoKey(S_Key) "此处使用自定义函数 AutoKey(),该函数为实现智能搜索的核心
RST.Open StrSQL,CNN,3,2 "得到搜索后的记录
If RST.BOF And RST.EOF Then
%>
<font color="#FF0000">未找到任何结果!!!</font>
<%
Else
%>
搜索名称为“<font color="#FF0000"><%= S_Key %></font>”的项,共找到 <font color="#FF0000"><%= RST.RecordCount %></font> 项:<p>
<%
While Not RST.EOF "遍历整个记录集,显示搜索到的信息并设置链接
%>
<!-- 此处可设为你所需要的链接目标 -->
<font style="font: 12pt 宋体"><a href="info.asp?ID=<%= RST("ID") %>" target="_blank"><%= RST("U_Name") %></a></font><br>
<!-- 显示部分详细内容 -->
<font style="font: 9pt 宋体"><%= Left(RST("U_Info"),150) %></font><p>
<%
RST.MoveNext
Wend
RST.Close
Set RST=Nothing
End If
End If
%>
<%
Function AutoKey(strKey)
CONST lngSubKey=2
Dim lngLenKey, strNew1, strNew2, i, strSubKey
"检测字符串的合法性,若不合法则转到出错页。出错页你可以根据需要进行设定。
if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,""")<>0 or InStr(strKey," ")<>0 or InStr(strKey," ")<>0 or InStr(strKey,""")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then
Response.Redirect "error.htm"
End If
lngLenKey=Len(strKey)
Select Case lngLenKey
Case 0 "若为空串,转到出错页
Response.Redirect "error.htm"
Case 1 "若长度为1,则不设任何值
strNew1=""
strNew2=""
Case Else "若长度大于1,则从字符串首字符开始,循环取长度为2的子字符串作为查询条件
For i=1 To lngLenKey-(lngSubKey-1)
strSubKey=Mid(strKey,i,lngSubKey)
strNew1=strNew1 & " or U_Name like "%" & strSubKey & "%""
strNew2=strNew2 & " or U_Info like "%" & strSubKey & "%""
Next
End Select
"得到完整的SQL语句
AutoKey="Select * from imgurl where url like "%" & strKey & "%" or title like "%" & strKey & "%"" & strNew1 & strNew2
End Function
%>
<%
CNN.Close
Set CNN=Nothing
%>
报错:
至少一个参数没有被指定值。 (指的是 RST.Open StrSQL,CNN,3,2 这一行)
/www/date/search.asp,行13
问题点数:30、回复次数:2Top
1 楼bbtflash(摆摆)回复于 2006-07-12 11:10:35 得分 30
在 RST.Open StrSQL,CNN,3,2 这一行前面加一行
response.write(StrSQL)
看看输出的结果是什么,是不是SQL语句的问题Top
2 楼chshhxyz012()回复于 2006-07-12 13:52:02 得分 0
谢谢您的提议,但是它不能追踪Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn
