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

asp与sql连接查询,只显示最后一条数据???
<%
sql= "select   *   from   db_business "

if   request( "username ") <> " "   then
sql=sql& "   where   d_name= '% "&request( "username ")& "% ' "
end   if
if   request( "d_time ") <> " "   then

sql=sql& "   or   d_time   between '% "&request( "time1 ")& "% '   and   '% "&request( "time2 ")& "% ' "
end   if
sql=sql& "   order   by   id   desc "
set   rs=server.createobject( "adodb.recordset ")
rs.Open   sql,   conn,   1,   1
%>
本人菜鸟,刚学asp,希望各位大大帮帮忙!

------解决方案--------------------
rs.movefirst

rs.movenext

用过没?
------解决方案--------------------
很多方法.
如上面所说的
top 然后 order by ... desc

这个是只取一行数据

或者可以用
rs.recordcount
来专门取其中的某些行特殊处理

甚至可以
<%m=0
do while not rs.eof

if m=?? then
end if

rs.movenext
m=m+1
loop
%>

这样来处理
处理的方式很多...
------解决方案--------------------
写法如下:

sql= "select * from db_business where 1=1 "

if request( "username ") <> " " then
sql=sql& " and d_name like '% "&request( "username ")& "% ' "
end if
if request( "d_time ") <> " " then

sql=sql& " or (d_time between ' "&request( "time1 ")& "% ' and ' "&request( "time2 ")& " ') "
end if
sql=sql& " order by id desc "
set rs=server.createobject( "adodb.recordset ")
rs.Open sql, conn, 1, 1
------解决方案--------------------
不好意思,我上面有个地方写错了
你一直都没说明白问题,查询方式有很多,时间、ID、各种大小等可以按照asc和desc顺序查询数据
order by id desc //从大到小
order by id asc //从小到大
按ID查询从100-1显示
set rs=server.createobject( "adodb.recordset ")
sql= "select * from db_business where 条件 order by id desc "
rs.Open sql, conn, 1, 1
//如果没有循环rs.movenext,这里只显示id=100的数据
rs.close

按ID查询从1-100显示
set rs=server.createobject( "adodb.recordset ")
sql= "select * from db_business where 条件 order by id asc "
rs.Open sql, conn, 1, 1
//如果没有循环rs.movenext,这里只显示id=1的数据
rs.close

就看你是怎么个查询方法了,要显示最后一条,不需要rs.movenext,也不需要top

------解决方案--------------------
<%
sql= "select * from db_business where 1=1 "
qstr= " "

if request( "d_name ") <> " " then
qstr=qstr& " and d_name= '% "&Replace(request( "username "), " ' ", " ' ' ")& "% ' "
end if
if request( "d_time ") <> " " then
qstr=qstr& " or d_time between ' "&Replace(request( "time1 "), " ' ", " ")& " ' and ' "&Replace(request( "time2 "), " ' ", " ")& " ' " ' '无需%号
end if
sql=sql&qstr& " order by id desc "