asp 字符串分割对应数据库的ID输出内容
把下面的字符串以逗号分割开,然后对应数据库的ID把相应的内容输出来,下面的代码只能输出一个值。为什么?哪里出现问题,还是.....请哪位高手会的帮帮忙啊Content = "2,8,12,18,40,41,42,43,44,45,46,47,48,49,51"
str = split(Content,",")
Set Rs2 = Server.CreateObject("ADODB.Recordset")
for i = 0 to ubound(str)
tSQL = "SELECT * FROM Tb_Sur_Option WHERE ID="&str(i)
Rs2.open tSQL,objConn,1,1
If Not Rs2.eof then
for j = 1 to Rs2.RecordCount
response.Write Rs2("OptionText")
Next
Rs2.movenext
End if
Next
追问:这样也不行呢Content = "2,8,12,18,40,41,42,43,44,45,46,47,48,49,51"
str = split(Content,",")
Set Rs = Server.CreateObject("ADODB.Recordset")
for i = 0 to ubound(str)
SQL = "SELECT * FROM Tb_Sur_Option WHERE ID IN("&Content&")"
Rs.open SQL,objConn,1,1
If Not Rs.eof then
response.Write Rs("ID")&"<br>"
End If
next
运行结果:15个2;如果输出的跟上面Content的数据一样的就对
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2