Dim i
For i = 1 to 10
Set objConn = Server.CreateObject(\"ADODB.Connection\")
objConn.Open Application(\"Conn\")
Set objRS = Server.CreateObject(\"ADODB.Recordset\")
objRS.ActiveConnection = objConn
objRS.CursorType = 0 ’adOpenForwardOnly
objRS.LockType = 1 ’adLockReadOnly
objRS.Open Application(\"SQL\")
If objRS.EOF Then
Response.Write(\"No Records Found\")
Else
’write headings
...
’write data
...
End If
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Next
第二,如ADO__05.asp所示,在循环外面创建Connection对象,所有记录集共享该对象:
Set objConn = Server.CreateObject(\"ADODB.Connection\")
objConn.Open Application(\"Conn\")
Dim i
For i = 1 to 10
Set objRS = Server.CreateObject(\"ADODB.Recordset\")
objRS.ActiveConnection = objConn
objRS.CursorType = 0 ’adOpenForwardOnly
objRS.LockType = 1 ’adLockReadOnly
objRS.Open Application(\"SQL\")
If objRS.EOF Then
Response.Write(\"No Records Found\")
Else
’write headings
...
’write data
...
End If
objRS.Close
Set objRS = Nothing
Next
objConn.Close
Set objConn = Nothing
第三,如ADO__06.asp所示,在每一个循环内把连接串赋给ActiveConnection属性:
Dim i
For i = 1 to 10
Set objRS = Server.CreateObject(\"ADODB.Recordset\")
objRS.ActiveConnection = Application(\"Conn\")
objRS.CursorType = 0 ’adOpenForwardOnly
objRS.LockType = 1 ’adLockReadOnly [Page]
objRS.Open Application(\"SQL\")
If objRS.EOF Then
文章来源于领测软件测试网 https://www.ltesting.net/