日期:2014-05-17  浏览次数:20848 次

我已经研究一周了,但愿不是犯低级错误!
高手们帮忙看下,这段程序为什么过不去。(Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e21' 

ODBC 驱动程序不支持所需的属性。)

Sql5的值是:Select * from shop_books where 1=1 and anclassid= '27' and bookname like '%m%' (注:27 和 m 都是搜索的值)

 
  dim connstr2
  connstr2="DBQ="+server.mappath("../database/mydb.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
  set conn2=server.createobject("ADODB.CONNECTION")
  conn2.open connstr2


  dim bigclass,smallclass,sheng,shi,name
  bigclass=trim(request("anclassid"))  
smallclass=trim(request("nclassid"))  
sheng=trim(request("dsheng"))  
shi=trim(request("dshi"))  
jiage=trim(request("jiage"))
name=trim(request("searchkey")) 
name=replace(name,"'","''") 



Sql5= " Select * from shop_books where 1=1 " 
set rs = conn2.execute(sql5)

  if bigclass <>"" then 
Sql5= Sql5 & " and anclassid= '"& bigclass &"'"
end if
if smallclass <>"" then
Sql5= Sql5 & " and nclassid= '"& smallclass &"'"
end if
if sheng <>"" then 
Sql5= Sql5 & " and dsheng= '"& sheng &"'" 
end if 
if shi <>"" then 
Sql5= Sql5&" and dshi= '"& shi &"'" 
end if 
if name <>"" then
Sql5= Sql5&" and bookname like '%"& searchkey &"%' " 
end if  
   
 

set rs=server.createobject("adodb.recordset") 
  rs.open Sql5,conn2,1,1

------解决方案--------------------
anclassid的字段类型是数字的话,不用两边的单引号.

------解决方案--------------------
你把 Sql5 打印出来瞅瞅
------解决方案--------------------
上面几位朋友说的没错,
你把最终拼接好的sql5代码用response.Write输出一下,然后把这条语句放到数据库的sql视图运行下看看是否正确
Sql5= " Select * from shop_books where 1=1 "

 
if bigclass <>"" then
Sql5= Sql5 & " and anclassid= "& bigclass
end if
if smallclass <>"" then
Sql5= Sql5 & " and nclassid= "& smallclass
end if
if sheng <>"" then 
Sql5= Sql5 & " and dsheng= "& sheng
end if 
if shi <>"" then 
Sql5= Sql5 &" and dshi= "& shi
end if 
if name <>"" then
Sql5= Sql5 &" and bookname like '%"&name&"%'"
end if


response.Write (sql5)
response.End()
先输出