asp select语句中的变量如何书写
<%Title=Request.Form("Title")s_county=CheckStr(Request.Form("s_county"))num=CheckStr(...
<%
Title=Request.Form("Title")
s_county=CheckStr(Request.Form("s_county"))
num=CheckStr(Request.Form("num"))
set rs1=server.createobject("ADODB.Recordset")
sql1="SELECT Top '&num&' * from [user] where s_county= '&s_county&' Order BY rnd(id)"
rs1.open sql1,conn,1,3
If Not rs1.Eof Then
do while not (rs1.eof or err)
%>
<%content=rs1("fullname")%>
<%
rs1.movenext
loop
end if
rs1.close
set rs1=nothing
%>
目的随机挑出数据库里 制定数量num及条件s_county的记录并把名字存到content里 展开
Title=Request.Form("Title")
s_county=CheckStr(Request.Form("s_county"))
num=CheckStr(Request.Form("num"))
set rs1=server.createobject("ADODB.Recordset")
sql1="SELECT Top '&num&' * from [user] where s_county= '&s_county&' Order BY rnd(id)"
rs1.open sql1,conn,1,3
If Not rs1.Eof Then
do while not (rs1.eof or err)
%>
<%content=rs1("fullname")%>
<%
rs1.movenext
loop
end if
rs1.close
set rs1=nothing
%>
目的随机挑出数据库里 制定数量num及条件s_county的记录并把名字存到content里 展开
1个回答
展开全部
sql1="SELECT Top '&num&' * from [user] where s_county= '&s_county&' Order BY rnd(id)"
改为
sql1="SELECT Top " & num & " * from [user] where s_county= '" & s_county & "' Order BY rnd(id)"
改为
sql1="SELECT Top " & num & " * from [user] where s_county= '" & s_county & "' Order BY rnd(id)"
追问
不知道为什么 一运行就死掉 也不报错!!
追答
s_county是字符型还是数值型的?如果是数值型,就改为
sql1="SELECT Top " & num & " * from [user] where s_county= " & s_county & " Order BY rnd(id)"
如果还是不行,那么问题就不是出在这里,是其他语句上
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询