如何在不使用Dreamweaver重复区域的情况下循环播放asp classic中的选定记录。
<%
Dim rs_pic
Dim rs_pic_cmd
Dim rs_pic_numRows
Set rs_pic_cmd = Server.CreateObject ("ADODB.Command")
rs_pic_cmd.ActiveConnection = MM_viva_web_STRING
rs_pic_cmd.CommandText = "SELECT * FROM dbo.users_pics ORDER BY u_pic_id DESC"
rs_pic_cmd.Prepared = true
rs_pic_cmd.Parameters.Append rs_pic_cmd.CreateParameter("param1", 5, 1, -1, rs_pic__lastmsg) ' adDouble
Set rs_pic = rs_pic_cmd.Execute
rs_pic_numRows = 0
%>
我知道重复区域做得很简单,但我想知道是否有一种方法可以在select语句中循环它
答案 0 :(得分:0)
使用Do
循环?
Set rs_pic = rs_pic_cmd.Execute
Do While Not rs_pic.EOF
'Access the record values here
Response.Write "u_pic_id = " & rs_pic("u_pic_id").Value
'Move to next record in the Recordset
rs_pic.MoveNext()
Loop
使用ADODB.Recordset
迭代记录更有效的另一种方法是使用2维数组。
Set rs_pic = rs_pic_cmd.Execute
'If we have data convert it to an array.
If Not rs_pic.EOF Then data = rs_pic.GetRows()
'Close and release Recordset object
Call rs_pic.Close()
Set rs_pic = Nothing
'Use Array to iterate the data
If IsArray(data) Then
'Get number of rows
rows = UBound(data, 2)
For row = 0 To rows
'Return first column of current row.
Response.Write data(0, row)
Next
Else
Response.Write "No records to display"
End If