| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1339 人关注过本帖
标题:各位帮我看看我的搜索功能哪里出问题了?
只看楼主 加入收藏
liu_libra
Rank: 2
等 级:论坛游民
帖 子:153
专家分:20
注 册:2008-10-13
结帖率:72.22%
收藏
 问题点数:0 回复次数:13 
各位帮我看看我的搜索功能哪里出问题了?
说明:共4个搜索条件,分别为class1,class2,城市和关键字
      其中class1 和class2 两者不同时为空,城市(province,city)和关键字(keywords)可以为空
代码如下,请帮我看看那里出问题了,错误提示为ADODB.Recordset (0x800A0BB9)参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。(连接数据库正确)或者有没有其他的方法可行。我觉得这样太复杂了,谢谢了!
<%
 set rs2=server.CreateObject("adodb.recordset")
 
if request("class1")="" and request("class2")<>"" then
   if request("province")="" and request("keywords")="" then
   sql="select * from  ad where class2='"&request("class2")&"'"
   else
     if request("province")<>"" and request("keywords")<>"" then
     sql="select * from  ad where class2='"&request("class2")&"' and province='"&request("province")&"' and city='"&request("city")&"' and keywords like '%"&request("keywords")&"%'"
     else
       if request("province")<>"" and request("keywords")="" then
       sql="select * from  ad where class2='"&request("class2")&"' and province='"&request("province")&"' and city='"&request("city")&"'"
       else
          if request("province")="" and request("keywords")<>"" then
          sql="select * from  ad where class2='"&request("class2")&"' and keywords like '%"&request("keywords")&"%'"
          end if
       end if
     end if
    end if
 else
 if request("class1")<>"" and request("class2")="" then
   if request("province")="" and request("keywords")="" then
   sql="select * from  ad where class1='"&request("class1")&"'"
   else
     if request("province")<>"" and request("keywords")<>"" then
     sql="select * from  ad where class1='"&request("class1")&"' and province='"&request("province")&"' and city='"&request("city")&"' and keywords like '%"&request("keywords")&"%'"
     else
       if request("province")<>"" and request("keywords")="" then
       sql="select * from  ad where class1='"&request("class1")&"' and province='"&request("province")&"' and city='"&request("city")&"'"
       else
          if request("province")="" and request("keywords")<>"" then
          sql="select * from  ad where class1='"&request("class1")&"' and keywords like '%"&request("keywords")&"%'"
          end if
        end if
      end if
    end if
 else
 if request("class1")<>"" and request("class2")<>"" then
   if request("province")="" and request("keywords")="" then
   sql="select * from  ad where class2='"&request("class2")&"' and class1='"&request("class1")&"'"
   else
      if request("province")<>"" and request("keywords")<>"" then
      sql="select * from  ad where class2='"&request("class2")&"'  and class1='"&request("class1")&"' and province='"&request("province")&"' and city='"&request("city")&"' and keywords like '%"&request("keywords")&"%'"
      else
        if request("province")<>"" and request("keywords")="" then
        sql="select * from  ad where class2='"&request("class2")&"' and class1='"&request("class1")&"' and province='"&request("province")&"' and city='"&request("city")&"'"
        else
          if request("province")="" and request("keywords")<>"" then
          sql="select * from  ad where class2='"&request("class2")&"'  and class1='"&request("class1")&"' and keywords like '%"&request("keywords")&"%'"
          end if
        end if
      end if
   end if
   end if
   end if
 end if

 rs2.open str,conn,1,1
%>
搜索更多相关主题的帖子: 搜索 
2008-10-16 12:41
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
我不看这么长的生成SQL语句的代码,你自己检查最后生成的SQL语句有没有问题……遇到问题再想怎么办
2008-10-16 13:35
hmhz
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:30
帖 子:1890
专家分:503
注 册:2006-12-17
收藏
得分:0 
完全可以这样写

if …… then
……
elseif …… then
……
end if

[编程论坛] ASP超级群:49158383  敲门暗号:ASP编程
龍艺博客 http://www.
2008-10-16 13:53
孤独冷雨
Rank: 10Rank: 10Rank: 10
来 自:安徽滁州
等 级:贵宾
威 望:23
帖 子:1247
专家分:1909
注 册:2007-6-4
收藏
得分:0 
先把要搜索的四个关键接收过来.再用IF判断写SQL语句.代码简单明了,你那样太乱了!
2008-10-16 14:20
liu_libra
Rank: 2
等 级:论坛游民
帖 子:153
专家分:20
注 册:2008-10-13
收藏
得分:0 
谢谢各位的指点,我再试试看
2008-10-16 15:05
lili0610
Rank: 2
等 级:新手上路
威 望:4
帖 子:197
专家分:0
注 册:2008-4-17
收藏
得分:0 
[free]sql="Select BellID,SongName,SingerName,Price,AvailabilityDate,SpName,Region,DownloadsNumber,DownloadsDate,YearMonth from DownloadsData where"
if music<>"" then sql=sql&" SongName like '%"&music&"%' AND"
if m_name<>"" then sql=sql&" SingerName like '%"&m_name&"%' AND"
if spname<>"" then sql=sql&" SpName like '%"&spname&"%' AND"
if region<>"" then sql=sql&" Region like '%"&region&"%' AND"
if date1<>"" and date2="" then sql=sql&" YearMonth ='"&date1&"-"&day1&"' AND"
if date2<>"" and date1="" then sql=sql&" YearMonth ='"&date2&"-"&day1&"' AND"
if date1<>"" and date2<>"" then sql=sql&" YearMonth >= '"&date1&"-"&day1&"' AND YearMonth <= '"&date2&"-"&day1&"' AND"
DownloadsDate>'"&month1&"' AND"
if right(sql,5)="WHERE" then sql=left(sql,clng(len(sql))-5) '解决所有参数都为空的情况
if right(sql,3)="AND" then sql=left(sql,clng(len(sql))-3) '去掉参数最后的and[/free]

用这个吧?我看比你的要好看明白的多,也没有你的麻烦
想怎么查询就怎么查询
这只是一种方法
2008-10-16 15:28
liu_libra
Rank: 2
等 级:论坛游民
帖 子:153
专家分:20
注 册:2008-10-13
收藏
得分:0 
我试试,谢谢6楼了!
2008-10-16 19:06
liu_libra
Rank: 2
等 级:论坛游民
帖 子:153
专家分:20
注 册:2008-10-13
收藏
得分:0 
我把搜索语句改成下面的代码了,可还是不行,错误提示仍为ADODB.Recordset (0x800A0BB9)参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。
弄了几天了,再次麻烦各位帮我看看吧,这次增加了一个搜索条件audit:
str="where audit='1'"
  if len(request("class1"))<>0 then
  str=str&"and class1='"&request("class1")&"'"
  end if
  if len(request("class2"))<>0 then
  str=str&"and class2='"&request("class2")&"'"
  end if
  if request("province")<>"0" then
  str=str&"and province='"&request("province")&"' and city='"&request("city")&"'"
  end if
  if len(request("keywords"))<>0 then
  str=str&"and  keywords like '%"&request("keywords")&"%'"
  end if
  set rs2=server.CreateObject("adodb.recordset")
  sql="select * from ad" &str
  rs2.open sql,conn,1,1
2008-10-17 16:43
nicechlk
Rank: 3Rank: 3
等 级:论坛游侠
威 望:4
帖 子:330
专家分:187
注 册:2008-9-6
收藏
得分:0 
错误提示仍为ADODB.Recordset (0x800A0BB9)参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。
这个问题应该不是你的代码问题
你应该检查一下数据库连接正确不?
有没有包含conn.asp(数据库连接文件)?
conn.asp样本:
<%dim conn,connstr
set conn = server.createobject("adodb.connection")
connstr= "provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source = " & Server.MapPath("****.mdb")
if err then
err.clear
else
conn.open connstr
end if
Sub closeconn()
    conn.close
    set conn=nothing
end sub
on error resume next%>

莫以善小而不为,莫以恶小而为之!
2008-10-17 18:45
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
怎么都不找本质联系呢……SQL语句不对不会提示这个错误。
2008-10-17 18:51
快速回复:各位帮我看看我的搜索功能哪里出问题了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012908 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved