| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 621 人关注过本帖
标题:查询中出现错误,不知道怎么回事!请指点!
只看楼主 加入收藏
han1202
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2006-4-12
结帖率:0
收藏
 问题点数:0 回复次数:5 
查询中出现错误,不知道怎么回事!请指点!

查询的代码:
<%
dim hotel_dq,hotel_name,hotel_qj,hotel_lx,hotel_level
hotel_dq=mfkiqpl.nosqlinject(trim(request.Form("hotel_dq")))
hotel_lx=mfkiqpl.nosqlinject(trim(request.Form("hotel_lx")))
hotel_name=mfkiqpl.nosqlinject(trim(request.Form("hotel_name")))
hotel_qj=mfkiqpl.nosqlinject(trim(request.Form("hotel_qj")))
sql="select id,hotel_name,hotel_city,hotel_level,hotel_price,hotel_price_1,hotel_photo,hotel_type,hotel_add,hotel_bio,hotel_dq from hotel where "
if hotel_dq<>"" then sql=sql&" hotel_dq='"&hotel_dq&"' "
if hotel_lx<>"" then sql=sql&" hotel_level='"&hotel_lx&"'"
if hotel_name<>"" then sql=sql&" hotel_name like '%"&hotel_name&"%' "
if hotel_qj<>"" then sql=sql&" hotel_price_1>"&hotel_qj&" "
set rs=server.CreateObject("ADODB.Recordset")
'selectsql=selectsql+1
rs.open sql,conn,1,2

%>
出现的错误:有时候全部能查出没有where的关系
有时候附近有语法错误

[此贴子已经被作者于2007-8-10 13:03:09编辑过]

搜索更多相关主题的帖子: hotel name Form trim 
2007-08-10 13:02
SkyGull
Rank: 5Rank: 5
来 自:浙江杭州
等 级:贵宾
威 望:13
帖 子:839
专家分:324
注 册:2007-6-7
收藏
得分:0 
[CODE]if hotel_dq<>"" then sqlwhere=" hotel_dq='"&hotel_dq&"' "
if hotel_lx<>"" then sqlwhere=" hotel_level='"&hotel_lx&"'"
if hotel_name<>"" then sqlwhere=" hotel_name like '%"&hotel_name&"%' "
if hotel_qj<>"" then sqlwhere=" hotel_price_1>"&hotel_qj&" "
sql="select id,hotel_name,hotel_city,hotel_level,hotel_price,hotel_price_1,hotel_photo,hotel_type,hotel_add,hotel_bio,hotel_dq from hotel where "&sqlwhere&""[/CODE]

这样换一下试一下
2007-08-10 13:32
han1202
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2006-4-12
收藏
得分:0 
这样不行吧,因为前面的那个数据库字根没有读取呀!
hotel_dq,hotel_level,hotel_name

怎么能读一下就好了
谢谢你了!
2007-08-10 13:51
SkyGull
Rank: 5Rank: 5
来 自:浙江杭州
等 级:贵宾
威 望:13
帖 子:839
专家分:324
注 册:2007-6-7
收藏
得分:0 
什么字根没有读取???

这样已经保证了sql语句的完整性了
2007-08-10 14:01
han1202
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2006-4-12
收藏
得分:0 
附近有语法错误
现在是单个的条件可以
多个的条件由于没有and联系出错语法不对
看样这个查询语句要大改动
有没有这样的四个条件的查询语句

谢谢了
2007-08-10 14:33
lq7350684
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:5089
专家分:98
注 册:2006-11-6
收藏
得分:0 
sql="select id,hotel_name,hotel_city,hotel_level,hotel_price,hotel_price_1,hotel_photo,hotel_type,hotel_add,hotel_bio,hotel_dq from hotel where 1=1"
if hotel_dq<>"" then sql=sql&" and hotel_dq='"&hotel_dq&"' "


类似这样写,试试看。
2007-08-10 16:20
快速回复:查询中出现错误,不知道怎么回事!请指点!
数据加载中...
 
   



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

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