| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 477 人关注过本帖
标题:模糊查询问题~不知道怎么改
只看楼主 加入收藏
xinzhilei
Rank: 1
等 级:新手上路
帖 子:49
专家分:5
注 册:2007-3-27
结帖率:0
收藏
 问题点数:0 回复次数:5 
模糊查询问题~不知道怎么改


index.asp:
<!--#include file="Conn/conn.asp"-->
<%
set rs=server.CreateObject("adodb.recordset")
sql="select userID from tab_user"
rs.open sql,conn,1,3
%>
<%
set rs1=server.CreateObject("adodb.recordset")
sql1="select username from tab_user"
rs1.open sql1,conn,1,3
%>
<%
set rs2=server.CreateObject("adodb.recordset")
sql2="select birthday from tab_user"
rs2.open sql2,conn,1,3
%>
<html>
<body>
<table width="526" border="0" cellpadding="0" cellspacing="0" align="center">
<form name="form1" method="post" action="delete_ok.asp" target="mainFrame">
<!--DWLayoutTable-->
<tr bgcolor="#0099CC">
<td width="526" height="6"></td>
</tr>
<tr bgcolor="#0099CC">
<td height="13" valign="top">用户查询系统>>>></td>
</tr>
<tr bgcolor="#0099CC">
<td height="9"></td>
</tr>
<tr bgcolor="#CCCCCC">
<td height="42" valign="top">
<input name="flag" type="radio" value="1" checked>用户名
<select name="select1" id="select2">
<%if not(rs.eof) then%>
<%for i=1 to rs.recordcount%>
<option value="<%=rs("userID")%>" selected><%=rs("userID")%></option>
<%rs.movenext
next
end if
%>
</select>
<input name="flag" type="radio" value="2" checked>用户名
<select name="kk1" id="kk2">
<%if not(rs1.eof) then%>
<%for i=1 to rs1.recordcount%>
<option value="<%=rs1("username")%>" selected><%=rs1("username")%></option>
<%rs1.movenext
next
end if
%>
</select>
<input name="flag" type="radio" value="3">
<input name="ff1" type="text">
<input name="bb" type="submit" class="submit" value="查询" >
</td>
</tr>
</form>
</table>

</body>
</html>

delete_ok.asp:
<!--#include file="Conn/conn.asp"-->
<%

flag=request("flag")
select1=request("select1")
kk1=request("kk1")
ff1=trim(request("ff1"))
set rs=server.CreateObject("adodb.recordset")
sql="select * from tab_user"
select case flag
case "1"
sql="select * from tab_user where userID='"&select1&"'"
case "2"
sql="select * from tab_user where username='"&kk1&"'"
case "3"
sql="select * from tab_user where username like %"&ff1&"%" '这句是不是有问题?
end select
rs.open sql,conn,1,3
%>
<table width="461" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="83" height="30" valign="top">ID</td>
<td width="87" valign="top">用户</td>
<td width="86" valign="top">性别</td>
<td width="94" valign="top">年龄</td>
<td width="111" valign="top">出生日子</td>
</tr>
<%if not(rs.eof)then%>
<%for i=1 to rs.recordcount%>
<tr>
<td height="30" valign="top"><%=rs("userID")%></td>
<td valign="top"><%=rs("username")%></td>
<td valign="top"><%=rs("sex")%></td>
<td valign="top"><%=rs("age")%></td>
<td valign="top"><%=rs("birthday")%></td>
<%rs.movenext
next
end if
%>
</tr>
</table>



好象是模糊那句有问题~不知道怎么改~

提示错误是:错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]第 1 行: '天' 附近有语法错误。
/jian/delete_ok.asp, 第 18 行

搜索更多相关主题的帖子: 模糊 查询 
2007-05-21 21:51
谁与争疯
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:海南省
等 级:版主
威 望:191
帖 子:15071
专家分:17513
注 册:2007-4-22
收藏
得分:0 

sql="select * from tab_user where username like %"&ff1&"%" '这句是不是有问题?

改成
sql="select * from tab_user where username like "&"%ff1%" //这句是不是有问题?


不知道上面能不能这样? 不然,我也帮不了你了。

[此贴子已经被作者于2007-5-21 22:02:33编辑过]


论坛是我家灌水靠大家
2007-05-21 21:59
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
sql="select * from tab_user where username like '%"&ff1&"%'" '这句是不是有问题?
个人记得模糊查询也是需要单引号的。
2007-05-21 22:36
谁与争疯
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:海南省
等 级:版主
威 望:191
帖 子:15071
专家分:17513
注 册:2007-4-22
收藏
得分:0 
版主高见。

论坛是我家灌水靠大家
2007-05-21 23:05
kidy2005
Rank: 1
等 级:新手上路
帖 子:107
专家分:0
注 册:2007-4-18
收藏
得分:0 
3楼的是正确的

恒天装饰网:http://www.
2007-05-22 11:13
laoshu1
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2007-4-14
收藏
得分:0 
顶了!楼上的说的对啊!3楼是正确的啊
2007-05-22 11:49
快速回复:模糊查询问题~不知道怎么改
数据加载中...
 
   



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

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