为什么我复合查询能查,单一查询就不能,各位我急用
<!--#include File="conn.asp"-->
<%
dim rs
'if request("action")="select" then
Set rs= Server.CreateObject("ADODB.RecordSet")
sqltext="where "
if request("listxuhao")<>0 then sqltext=sqltext&"listxuhao="&request("listxuhao")&" and "
if request("listname")<>"" then sqltext=sqltext&"listname='"&request("listname")&"' and "
'response.write sqltext
'response.end
if request("listsex")<>50 then sqltext=sqltext&"listsex="&request("listsex")&" and "
'response.write sqltext
'response.end
if request("meizhu")<>"" then sqltext=sqltext&"meizhu='"&request("meizhu")&"' and "
'if request("chushen")<>"" and request("chushen1")<>50 then sqltext=sqltext&"chushen"&request("chushen1")request("chushen")&" and "
if request("mianmao")<>0 then sqltext=sqltext&"mianmao="&request("mianmao")&" and "
if request("wenhua1")<>0 then sqltext=sqltext&"wenhua1="&request("wenhua1")&" and "
if request("xuewei1")<>0 then sqltext=sqltext&"xuewei1="&request("xuewei1")&" and "
if request("biye1")<>"" then sqltext=sqltext&"biye1='"&request("biye1")&"' and "
if request("zhuanye1")<>"" then sqltext=sqltext&"zhuanye1='"&request("zhuanye1")&"' and "
if request("beizhu")<>"" then sqltext=sqltext&"beizhu='"&request("beizhu")&"' and "
if request("wenhua2")<>0 then sqltext=sqltext&"wenhua2="&request("wenhua2")&" and "
if request("xuewei2")<>0 then sqltext=sqltext&"xuewei2="&request("xuewei2")&" and "
if request("biye2")<>"" then sqltext=sqltext&"biye2='"&request("biye2")&"' and "
if request("zhuanye2")<>"" then sqltext=sqltext&"zhuanye2='"&request("zhuanye2")&"' and "
if request("xianzhi")<>"" then sqltext=sqltext&"xianzhi='"&request("xianzhi")&"' and "
if request("jibei")<>0 then sqltext=sqltext&"jibei="&request("jibei")&" and "
if request("lizhi")<>0 then sqltext=sqltext&"lizhi="&request("lizhi")&" and "
exec="select * from list "&sqltext&" 1=1 order by list_id"
'response.write exec
'response.end
'exec="select * from list where listsex='"&request("listsex")&"'order by list_id"
rs.Open exec, Conn, 3,3
dim currentpage
currentpage=Request("currentpage")
if currentpage=0 then
currentpage=1
end if
RecordCount = 0
do while not rs.Eof
RecordCount = RecordCount +1
rs.MoveNext
loop
if not RecordCount=0 then
rs.MoveFirst
end if
pageCount1=RecordCount/25
pageCount1=int(pageCount1)
if (RecordCount mod 25)>0 then
pageCount1=pageCount1 +1
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>显示市直机关内部机构及干部情况表</title>
</head>
<style type="text/css">
<!--
.main { font-size: 14pt}
.in{
font-size: 12px;
background-color: #DDF0FF;
border: 1px dotted #000000;
background-position: center center;
}
body { text-align: center}
td { font-size: 9pt}
-->
</style>
<body>
<script language=javascript>
function SureDel(id)
{
if ( confirm("警告!是否要删除?"))
{
window.location.href = "dellistren.asp?id=" + id
}
}
</script>
<table width="54%" border="0" align="center" cellpadding="0" cellspacing="3">
<tr>
<td bgcolor="#CCCCCC"><a href="listren.asp">
<div align="center">显示</div>
</a></td>
<td bgcolor="#CCCCCC"><a href="addlistren.asp">
<div align="center">添加</div>
</a></td>
</tr>
</table>
<br>
<br>
<table width="855" height="470" border="0" cellpadding="0" cellspacing="0"
bgcolor="#99CCCC">
<tr>
<td valign="top">
<br>
<table width="837" height="54" border="0" align="center" cellpadding="0"
cellspacing="1" bgcolor="#999999">
<tr bgcolor="#99CCCC">
<td colspan="6">
<div align="center"><font color="#990099">显示记录</font></div></td>
</tr>
<tr>
<td width="141" align="center" bgcolor="#99CCCC"><font color="#990099">序号
</font></td>
<td width="141" align="center" bgcolor="#99CCCC"><font color="#990099">姓名
</font></td>
<td width="141" align="center" bgcolor="#99CCCC"><font color="#990099">性别
</font></td>
<td width="141" align="center" bgcolor="#99CCCC"><font color="#990099">政治面貌
</font></td>
<td width="141" align="center" bgcolor="#99CCCC"><font color="#990099">现任职务
</font></td>
<td width="141" align="center" bgcolor="#99CCCC"><font color="#990099">操作
</font></td>
</tr>
<%do while pos<(currentpage-1)*25
pos=pos+1
rs.moveNext
loop%>
<%x=0%>
<% do while x<25 and not rs.eof %>
<tr>
<td width="141" align="center" bgcolor="#99CCCC" ><%=rs("listxuhao")%></td>
<td width="141" align="center" bgcolor="#99CCCC"><%=rs("listname")%></td>
<td width="141" align="center" bgcolor="#99CCCC"><%if rs("listsex")="0" then
response.write "女"
else
response.write "男"
end if %></td>
<td width="141" align="center" bgcolor="#99CCCC"><%=rs("mianmao")%></td>
<td width="141" align="center" bgcolor="#99CCCC"><%=rs("xianzhi")%></td>
<td width="141" align="center" bgcolor="#99CCCC"><a href="exitlistren.asp?
list_id=<%=rs("list_id")%>">修改</a> <a href='javascript:SureDel("<%=trim(rs("list_id"))%>")'> 删除</a></td>
</tr>
<%x=x+1
rs.movenext
loop%>
</table>
<br>
<br>
<table width="682" cellspacing="0" cellpadding="0" align="center" height="20">
<tr>
<td width="122" height="31">共有<%=RecordCount%>人/共<%=pageCount1%>页</td>
<td width="114" height="31">
<div align="center">
<% if currentpage=1 then %>
首页
<% else %>
<a href = chaxunlist.asp>首页</a>
<% end if %>
</div>
</td>
<td width="152" height="31">
<div align="center">
<% if currentpage=1 then %>
前一页
<% else %>
<a href ="chaxunlist.asp?currentpage=<%=currentpage-1%>">前一页 </a>
<% end if %>
</div>
</td>
<td width="142" height="31">
<div align="center">
<% if (not(pageCount1-currentpage<=0)) then %>
<a href = "chaxunlist.asp?currentpage=<%=currentpage+1%>">后一页 </a>
<% else %>
后一页
<% end if %>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
问题点数:0、回复次数:6Top
1 楼jbj001(贾不假)回复于 2003-11-01 13:42:25 得分 0
select * from list "&sqltext&" 1=1 order by list_id
?????
这么写???Top
2 楼Brookes(边走边唱)回复于 2003-11-01 13:45:11 得分 0
一定是你的sql写的有问题,在不正常情况监视一下该句Top
3 楼yywxlb(幽悠)回复于 2003-11-01 13:51:16 得分 0
在单一查询时候response.write (sql)把sql打印出来看看,错在那里了.Top
4 楼sjzxj(sjzxj)回复于 2003-11-01 13:52:53 得分 0
我有点不明白在你这条语句(if request("listsex")<>50 then sqltext=sqltext&"listsex="&request("listsex")&" and "
)里的listsex是数字,而在你的另外一条('exec="select * from list where listsex='"&request("listsex")&"'order by list_id")里是汉字了,你把它('"&request("listsex")&"')里面的单引号去了看看行吗。
Top
5 楼sjzxj(sjzxj)回复于 2003-11-01 13:55:17 得分 0
还有这里('exec="select * from list where listsex='"&request("listsex")&"'order by list_id")是空格是不是缺了,我说的是order前边!!Top
6 楼Tal(Tal)回复于 2003-11-01 14:56:19 得分 0
dim rs
Set rs= Server.CreateObject("ADODB.RecordSet")
sqltext=" where "
if request("listxuhao") <> "0" then sqltext = sqltext & " listxuhao='" & request("listxuhao")&"' and "
if request("listname") <> "" then sqltext = sqltext & " listname='" & request("listname") & "' and "
if request("listsex") <> "50" then sqltext = sqltext & " listsex='" & request("listsex") & "' and "
if request("meizhu") <> "" then sqltext = sqltext & " meizhu='" & request("meizhu") & "' and "
if request("mianmao") <> "0" then sqltext = sqltext & " mianmao='" & request("mianmao") & "' and "
if request("wenhua1") <> "0" then sqltext = sqltext & " wenhua1='" & request("wenhua1") & "' and "
if request("xuewei1") <> "0" then sqltext = sqltext & " xuewei1='" & request("xuewei1") & "' and "
if request("biye1") <> "" then sqltext = sqltext & " biye1='" & request("biye1") & "' and "
if request("zhuanye1") <> "" then sqltext = sqltext & " zhuanye1='" & request("zhuanye1") & "' and "
if request("beizhu") <> "" then sqltext = sqltext&" beizhu='" & request("beizhu") & "' and "
if request("wenhua2") <> "0" then sqltext = sqltext&" wenhua2=" & request("wenhua2") & " and "
if request("xuewei2") <> "0" then sqltext = sqltext&" xuewei2=" & request("xuewei2") & " and "
if request("biye2") <> "" then sqltext = sqltext&" biye2='" & request("biye2") & "' and "
if request("zhuanye2") <> "" then sqltext = sqltext & " zhuanye2='" & request("zhuanye2") & "' and "
if request("xianzhi") <> "" then sqltext = sqltext & " xianzhi='" & request("xianzhi") & "' and "
if request("jibei") <> "0" then sqltext = sqltext & " jibei=" & request("jibei") & "' and "
if request("lizhi") <> "0" then sqltext = sqltext & " lizhi='" & request("lizhi") & "' and "
exec="select * from list " & sqltext & " 1=1 order by list_id "
'response.write exec
'response.end
'exec="select * from list where listsex='"&request("listsex")&"'order by list_id"
rs.Open exec, Conn, 3,3Top




