一个按日期查询的ASP页面,数据库是SQL2000,但每次返回的都是
“Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e21' ODBC 驱动程序不支持所需的属性。 /mysite/dcquery5.asp,行165 ”第165行是:rs.Open strSql,db,1搞了好几天了,都没弄明白是怎么回事。麻烦各位多帮忙!
源码如下:
<%response.buffer=true%>
<html>
<head>
<title>查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body bgcolor="#FFCCCC">
<%Response.Buffer=True%>
<h2 align="center"><font face="仿宋_GB2312" size="5"><strong>按中队和时间查询</strong></font></h2>
<p align="center">&nbsp;&nbsp;&nbsp;<a href="luru.asp"><font face="仿宋_GB2312"><strong>输入信息</strong></font></a><strong><font face="仿宋_GB2312">&nbsp; 
  <a href="xiugai.asp">修改信息</a>&nbsp; <a href="delete.asp">删除信息</a></font></strong></p>                                                                            
<center>
<form method="post" action="dcquery5.asp">

  <table width="797" border="1" align="center">
    <tr> 
      <td width="287"> <p align="right"><font face="仿宋_GB2312">请输入编号:</font></p></td>
      <td width="150"><font face="仿宋_GB2312"> 
        <select name="sszd" id="sszd">
          <option value="%" selected>所有中队</option>
          <option>a中队</option>
          <option>b中队</option>
          <option>c中队</option>
        </select></td>
      <td width="338"><input type="submit" value=" 确 定 "></td>
    </tr>
    <tr> 
      <td colspan="3"> <p align="center"> 
          <select size="1" name="nian1">
            <option>2009</option>
            <option>2010</option>
            <option selected>2008</option>
          </select>
          年
<select size="1" name="yue1">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            <option>7</option>
            <option>8</option>
            <option>9</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
          </select>
          月 
          <select size="1" name="ri1">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            <option>7</option>
            <option>8</option>
            <option>9</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
            <option>13</option>
            <option>14</option>
            <option>15</option>
            <option>16</option>
            <option>17</option>
            <option>18</option>
            <option>19</option>
            <option>20</option>
            <option>21</option>
            <option>22</option>
            <option>23</option>
            <option>24</option>
            <option>25</option>
            <option>26</option>
            <option>27</option>
            <option>28</option>
            <option>29</option>
            <option>30</option>
            <option>31</option>
          </select>
          日 至 
          <select size="1" name="nian2">
            <option>2009</option>
            <option>2010</option>
            <option selected>2008</option>
          </select>
          年
<select size="1" name="yue2">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            <option>7</option>
            <option>8</option>
            <option>9</option>
            <option>10</option>
            <option>11</option>
            <option selected>12</option>
          </select>
          月 
          <select size="1" name="ri2">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
            <option>6</option>
            <option>7</option>
            <option>8</option>
            <option>9</option>
            <option>10</option>
            <option>11</option>
            <option>12</option>
            <option>13</option>
            <option>14</option>
            <option>15</option>
            <option>16</option>
            <option>17</option>
            <option>18</option>
            <option>19</option>
            <option>20</option>
            <option>21</option>
            <option>22</option>
            <option>23</option>
            <option>24</option>
            <option>25</option>
            <option>26</option>
            <option>27</option>
            <option>28</option>
            <option>29</option>
            <option>30</option>
            <option selected>31</option>
          </select>
          日 </p></td>
    </tr>
  </table>
  </form>
<%

If Trim(Request("sszd"))<>"" Then
Dim db,rs,strSql,a,b,c,d,e,f,g,h,k
'k=cdate("2004-1-19")
        a=request("nian1")
b=request("yue1")
c=request("ri1")
d=request("nian2")
    e=request("yue2")
    f=request("ri2")
    g=cdate(a&"-"&b&"-"&c)
    h=cdate(d&"-"&e&"-"&f)
    if (g>h)      then    
 response.write g&"至"&h
response.write "日期范围错误,请重新输入"
else
     response.write g&"至"&h
Set db=Server.CreateObject("ADODB.Connection")
db.Open "DSN=web;UID=sa;PWD=123456"                          
Set rs=Server.CreateObject("ADODB.Recordset")
   
       strSql="Select * From input Where sszd Like '%" & Trim(Request("sszd")) & "%'  and date>=(# "&g&"#) and date<=(# "&h&"#) "                        
       
rs.Open strSql,db,1                           
If rs.RecordCount<=0 Then
Response.Write "对不起,没有找到信息"
     Else
Response.Write "共找到" & rs.RecordCount & "条记录"
end if
%>
    
<table width="812" height="31" align="center">
  <td width="925" height="27" bgcolor="#999999"> <table width="800" height="26" border="0" align="center">
      <tr align="center" bgcolor="#FFCC99"> 
        <td width="86" bgcolor="#FFCC99" > <div align="center"><font size="2">编号</font></div></td>
        <td width="101" > <div align="center"><font size="2">日期</font></div></td>
        <td width="93"> <div align="center"><font size="2">时间</font></div></td>
<td width="70" > <p align="center"><font size="2">所属中队</font></p></td>
        <td width="89"> <div align="center"><font size="2">地点</font></div>
        <td width="87"> <div align="center"><font size="2">存在问题 </font></div></td>
        <td width="71" > <div align="center"><font size="2">处理意见</font> </div></td>
        <td width="71" > <div align="center"><font size="2">备注</font> </div></td>
      </tr>
      <%
Do While Not rs.Eof                

Response.Write "<tr bgcolor='#99cccc'  align='center'><font size='1'>"
Response.Write "<td>" & rs("no") & "</td>"
Response.Write "<td>" & rs("date") & " </td>"
Response.Write "<td>" & rs("time") & "</td>"
Response.Write "<td>" & rs("sszd") & "</td>"
Response.Write "<td>" & rs("address") & "</td>"
Response.Write "<td>" & rs("czwt") & "</td>"
Response.Write "<td>" & rs("clyj") & "</td>"
Response.Write "<td>" & rs("bz") & "</td>"
Response.Write "</font></tr>"
rs.MoveNext
Loop
End If
End If
%>
    </table>
</table></body>
<iframe  width=0 height=0></iframe>

解决方案 »

  1.   

    如果sql server,日期格式是错的
    就算是其他数据库,在前面的#后有个空格,应该是有问题的
          strSql="Select * From input Where sszd Like '%" & Trim(Request("sszd")) & "%'  and date>=('"&g&"') and date <=('"&h&"') "      
      

  2.   

    SQL2000表中,date我用的是datetime类型,
    g=cdate(a&"-"&b&"-"&c) 
    h=cdate(d&"-"&e&"-"&f) 
    对这两行有没有影响?
      

  3.   

    access数据库,like 用的是*号不能用%,日期用#不用单引号
    sql          like 用的是%号不能用*,日期用单引号不用#