请各位高手帮忙看看,以下是我的一个文件搜索页面,是按关键字和日期同时满足两都条件进行的搜索
程序存在有两个问题:
1.错误类型:
ADODB.Recordset (0x800A0BB9)
参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。
/hqjtims/searchdoc.asp, 第 29 行rs.open,conn,1,1为出错语句
2.程序中有**年至**年的搜索功能
我用range1和range2分别接收提交的内容,但不知道怎么实现用一个变量来接收上述二者的内容
代码如下:
<!--#include file = "conn.asp" -->
<%
if session("admin") = "" then
response.redirect "logincha.asp"
response.end
end if
Dim sKeyWord,sRange,range1,range2,keyword,page
sKeyWord = trim(request.form("keyword"))
range1 = GetSafeStr(Trim(Request("range1")))
range2 = GetSafeStr(Trim(Request("range2")))
if sKeyWord<>"" then
sKeyWord = ReplaceBadChar(sKeyWord) '过滤非法的SQL字符
else
sKeyWord = trim(request.querystring("keyword"))
end if
if( range1 = "" ) then
range1 = trim(request.querystring("range1"))
end if
if( range2 = "" ) then
range2= trim(request.querystring("range2"))
end if
dim sql,nPage,i,nCurCount,ID
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,3,3
sql = "select ID,FileName,Btime from News where FileName like '%"&sKeyWord&"%' and Btime between #"&range1&"# and #"&range2&"# Order By ID desc"
nPage = request.form("page")
if( nPage = "" ) then
nPage = request.querystring("page")
if( nPage = "" ) then
nPage = "1"
end if
end if
if( IsNumeric(nPage) = false )then '页码非数字类型时
nPage = 1
end if
nPage = Clng(nPage)
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="Css.css">
<title>文件信息搜索</title>
<Script Language="Javascript">
function unSelectAll()
{
if(document.myform.chkAll.checked){ //选中所有状态已经选择时,再取消一个单元的选择时
document.myform.chkAll.checked = document.myform.chkAll.checked&0; //原状态取反
}
}
function CheckAll()
{
for (var i=0;i<document.myform.elements.length;i++)
{
var e = document.myform.elements;
if (e.Name != "chkAll"&&e.disabled==false) //非chkAll单元且可操作的单元状态设置
e.checked = document.myform.chkAll.checked;
}
}
function ConfirmDel()
{
var flag = false;
for(var i=0; i < document.myform.elements.length; i++)
{
if(document.myform.elements.checked){
flag = true;
break;
}
}
if( flag == false )
return false;
if(confirm("确定要彻底删除选中的信息吗?一旦删除将不能恢复!"))
return true;
else
return false;
}
</Script>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><b>文件搜索</b></div></td>
</tr>
<tr>
<td><hr size="1"></td>
</tr>
</table>
<form name="SearchForm" method="post" action="search.asp?action=search"> <!--信息搜索表单-->
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#999999">
<tr>
<td bgcolor="#F5C84E"> 1、请输入关键字:
<input type="text" name="keyword">
2、请选择检索时间:
<select name="range1" size="1" id="select2">
<option value="2005-01-01">2005-01-01</option>
<option value="2005-07-01">2005-07-01</option>
<option value="2006-01-01">2006-01-01</option>
<option value="2006-07-01">2006-07-01</option>
<option value="2007-01-01">2007-01-01</option>
<option value="2007-07-01">2007-07-01</option>
<option value="2008-01-01">2008-01-01</option>
<option value="2008-07-01">2008-07-01</option>
<option value="2009-01-01">2009-01-01</option>
<option value="2009-07-01">2009-07-01</option>
</select>
至
<select name="range2" size="1" id="range2">
<option value="2005-06-30">2005-06-30</option>
<option value="2005-12-31">2005-12-31</option>
<option value="2006-06-30">2006-06-30</option>
<option value="2006-12-31">2006-12-31</option>
<option value="2007-06-30">2007-06-30</option>
<option value="2007-12-31">2007-12-31</option>
<option value="2008-06-30">2008-06-30</option>
<option value="2008-12-31">2008-12-31</option>
<option value="2009-06-30">2009-06-30</option>
<option value="2009-12-31">2009-12-31</option>
</select>
3、请点击
<input name="search" type="submit" id="search" value="搜索"></td>
</tr>
</table>
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td> 你输入的关键字为:<font color="#ff0000"><strong><%=sKeyWord%></strong></font>,所选择的检索范围为:<font color="#ff0000"><strong><%=range1%></strong></font>,搜索结果如下表所示:</td>
</tr>
</table>
<%
if( rs.eof ) then
response.write "<H1><div align='center'>没有找到任何合适的信息!</div></H1>"
else
%>
<!-- 表单开始 -->
<form name="myform" method="Post" action="deletedoc.asp?page=<%=nPage%>&action=select" onsubmit="return ConfirmDel();">
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#999999">
<tr bgcolor="#E1E1E1">
<td width="6%"><div align="center">状态</div></td>
<td width="46%"><div align="center">文件名</div></td>
<td width="12%"><div align="center">加入时间</div></td>
<td width="8%"><div align="center">修改</div></td>
<td width="8%"><div align="center">删除</div></td>
</tr>
<%
rs.pagesize = 20
if( nPage<1 or nPage>rs.pagecount ) then
nPage = 1
end if
rs.absolutepage = nPage
if( (nPage = rs.pagecount) and (rs.recordcount mod rs.pagesize <> 0) ) then
nCurCount = rs.recordcount mod rs.pagesize '计算当前页中含有的记录条数
else
nCurCount = rs.pagesize '当当前页不为最后一页时,都将含有pagesize条
end if
for i=1 to nCurCount
%>
<tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor=''" onmouseover="this.style.backgroundColor='#F7F8F8'">
<td><div align="center">
<input name="sNewsID" type="checkbox" id="sNewsID" value="<%=rs("ID")%>" onClick="unSelectAll()">
</div></td>
<td><a href="show.asp?id=<%=rs("ID")%>&page=<%=nPage%>"><%=rs("FileName")%></a></td>
<td><div align="center"><%=rs("Btime")%></div></td>
<td><div align="center"><a href="edit.asp?id=<%=rs("ID")%>&page=<%=nPage%>">修改</a></div></td>
<td><div align="center"><a href="deletedoc.asp?id=<%=rs("ID")%>&page=<%=nPage%>&action=one">删除</a></div></td>
</tr>
<%
rs.movenext
next
%>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td><div align="center"><%
response.write "总共<font color='#ff0000'>"&rs.recordcount&"</font>篇,"
response.write "目前是<font color='#ff0000'>"&nPage&"/"&rs.pagecount&"</font>页"
response.write " "
if( nPage = 1 ) then
response.write "【首页】"
response.write "【上一页】"
else
response.write "<a href='searchdoc.asp?page=1&keyword="&sKeyWord&"&range="&sRange&"'>【首页】</a>"
response.write "<a href='searchdoc.asp?page="&nPage-1&"&keyword="&sKeyWord&"&range="&sRange&"'>【上一页】</a>"
end if
if( nPage = rs.pagecount ) then
response.write "【下一页】"
response.write "【尾页】"
else
response.write "<a href='searchdoc.asp?page="&nPage+1&"&keyword="&sKeyWord&"&range="&sRange&"'>【下一页】</a>"
response.write "<a href='searchdoc.asp?page="&rs.pagecount&"&keyword="&sKeyWord&"&range="&sRange&"'>【尾页】</a>"
end if
%></div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><hr></td>
</tr>
<tr>
<td>
<input name="chkAll" type="checkbox" id="chkAll" value="checkbox" onClick="CheckAll()"><!--表单元的名不能与函数同名-->
全选/取消全选
<input type="submit" name="Submit" value=" 删除所选 "></td>
</tr>
</table>
</form>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#999999">
<form action="searchdoc.asp?keyword=<%=sKeyWord%>&range=<%=sRange%>" method="post" name="formpage" id="formpage">
<tr>
<td bgcolor="#E1E1E1"> 转到:
<input name="page" type="text" class="input_text" id="page" size="6">
页
<input type="submit" name="Submit" value="提交"></td>
</tr>
</form>
</table>
<%end if%>
</body>
</html>
<%
rs.close
%>