主题:  关于多条件查询问题!

czhgz

职务:普通成员
等级:1
金币:0.0
发贴:54
#12005/3/24 18:02:50
数据库是access的,
查询见面:



请看看下面的程序,

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/conn.asp" -->
<%dim sql%>
<%
Dim advance__varstartyear
advance__varstartyear = "2002"
if (request("startyear" <> "" then advance__varstartyear = request("startyear"
%>
<%
Dim advance__varendyear
advance__varendyear = "2003"
if (request("endyear" <> "" then advance__varendyear = request("endyear"
%>
<%sql="(r_date between #" + Replace(advance__varstartyear, "'", "''" + "# and #" + Replace(advance__varendyear, "'", "''" + "# ) "%>
<%
Dim advance__varleixing
if (request("leixing"<> "" then
advance__varleixing = request("leixing"
sql=sql+"and ( leixing = '" + Replace(advance__varleixing, "'", "''" + "')"
end if
%>
<%
Dim advance__varcbs
if (request("cbs" <> "" then
advance__varcbs = request("cbs"
sql=sql+"and ( cbs = '" + Replace(advance__varcbs, "'", "''" + "')"
end if
%>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape"&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">

<%dim a_description
if (request("fault"<>"" then
a_description=request("fault"
sql=sql+"and (((description like '%"&a_description&"%') or (result like '%"&a_description&"%'))"

end if
%>
<%dim a_description1
if (request("fault1"<>"" then
a_description1=request("fault1"
sql=sql+"and ((description like '%"&a_description1&"%') or (result like '%"&a_description1&"%'))"

end if
%>
<%dim a_description2
if (request("fault2"<>"" then
a_description2=request("fault2"
sql=sql+"and ((description like '%"&a_description2&"%') or (result like '%"&a_description2&"%'))"

end if
%>
<%
if (request("fault"<>"" then
sql=sql+""
end if
%>
<%
Dim adcance
Dim adcance_numRows

Set adcance = Server.CreateObject("ADODB.Recordset"
adcance.ActiveConnection = MM_conn_STRING
adcance.Source = "SELECT * FROM book WHERE"+ sql+ " ORDER BY r_date DESC"
adcance.CursorType = 0
adcance.CursorLocation = 2
adcance.LockType = 1
adcance.Open()
adcance_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
adcance_numRows = adcance_numRows + Repeat1__numRows
%>
<table width="897" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="68" valign="top" width="895" bgcolor="#336699">
<p align="center">
        <img border="0" src="../../网站/pic/Pi_22550.gif" style="position: absolute; left: 328; top: 39; width:119px; height:59px" width="119" height="59"><img border="0" src="../../网站/pic/banner.gif" width="474" height="93"></td>
</tr>
<tr>
<td height="496" valign="top" width="895">
<div align="center">
<img border="0" src="../../网站/pic/book1.gif" style="position: absolute; left: 186; top: 112" width="140" height="68">
<div style="position: absolute; left: 49px; top: 56px; width: 214; height: 34; z-index: 3">
<P><A href="index.htm"><font size="2" color="#ffffff">首页</font></A>
            <a href="index1.htm"> <font size="2" color="#ffffff">
图书阅览</font></a> <A href="searchbook.asp"><font size="2" color="#FFFFFF">图书特搜</font></A></P>
</div>

<p align="center"> </p>

<p align="center">以下是您的搜索结果(<a href="图书特.asp">重新查询</a></p>
<div align="center">
<table width="99%" border="2" height="52">
<tr bgcolor="#FFCC99">
<td width="6%" height="20" align="center"> &nbsp; <b><font face="宋体" size="3">编号</font></b>
</td>
<td width="10%" height="20" align="center"> <p align="center"><font size="2">&nbsp;</font><b><font size="3">类型</font></b>
</td>
<td width="21%" height="20" align="center"> <div align="center">
<p align="center"><b><font face="宋体" size="3">书名</font></b></div></td>
<td width="12%" height="20"> <div align="center"><b><font size="3">出版社</font></b></div></td>
<td width="5%" height="20" align="center"> <p align="center"><b><font face="宋体" size="3">业数</font></b>
</td>
<td width="5%" height="20" align="center"> <b><font size="3">单价</font></b></td>
<td width="11%" height="20" align="center"> <b><font face="宋体" size="3">原有数量</font></b>
</td>
<td width="11%" height="20" align="center"> <font size="3"><b>现有数量</b></font>
</td>
<td width="9%" height="20" align="center"> <font size="3"><b>借阅人</b></font>
</td>
<td width="10%" height="20" align="center"> <div align="center"><font face="宋体" size="2"><b>接收日期</b></font></div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT adcance.EOF))
%>
<tr>
<td width="6%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("bookid".value)%></font></td>
<td width="10%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("leixing".value)%></font></td>
<td width="21%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("description".value)%></font></td>
<td width="12%" height="22"><font face="宋体" size="2">
<p align="center"><%=(adcance.Fields.Item("cbs".value)%></font></td>
<td width="5%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("result".value)%></font></td>
<td width="5%" height="22" align="center"><%=(adcance.Fields.Item("jia".value)%>&nbsp;&nbsp;</td>
<td width="11%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("ys".value)%></font></td>
<td width="11%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("xs".value)%></font></td>
<td width="9%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("jieyueren".value)%></font></td>
<td width="10%" height="22" align="center"><font face="宋体" size="2"><%=(adcance.Fields.Item("r_date".value)%></font></td>
</tr>
<%
dim n
n=n+1
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
adcance.MoveNext()
Wend
%>
</table>
</div>
<p> </p>
<p> </p>
</div>
</td>
</tr>
</table>
<div align="center"> 共有<%=n%>项符合查询条件的项目</div>
</body>
</html>
<%
adcance.Close()
Set adcance = Nothing
%>





浏览器提示错误!


Microsoft VBScript 编译器错误 错误 '800a03f6'

缺少 'End'

/iisHelp/common/500-100.asp,行242

Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e14'

[Microsoft][ODBC Microsoft Access Driver] 日期的语法错误 在查询表达式 '(r_date between #1998# and #2003# ) and ( leixing = '词典类')' 中。

/searchbook_result4.asp,行83



czhgz

职务:普通成员
等级:1
金币:0.0
发贴:54
#22005/3/24 18:08:33
) 是右括号了的。怎么变成这样了



上一张查询图


图片如下:



沉默是金

职务:普通成员
等级:6
金币:11.2
发贴:4357
#32005/3/25 14:23:17
日期的语法错误 在查询表达式 '(r_date between #1998# and #2003# ) and ( leixing = '词典类')'

错误已经描述出来了,好久没用ACCESS,日期查询的操作府丢失,你把你的查询语句输出后放到ACCESS的查询窗体里去运行一下。


难人一个……

沉默是金

职务:普通成员
等级:6
金币:11.2
发贴:4357
#42005/3/25 14:27:30
一不小心搜索到仙鹤的一篇文章,有介绍如何进行多条件查询的方法,给你引荐一下。
xxol.net/2004/11-19/8571.htm


难人一个……