log=pubs; Data Source=ICBCZJP"
Set rsTest = Server.CreateObject("ADODB.Recordset")
'检索多个记录集
StrSQL = "Select COUNT(*) AS '雇员数' From employee; Select * From jobs"
rsTest.Open StrSQL, Cnn ', , ,adCmdText
While Not rsTest Is Nothing
Response.Write "<Table Border = 2><tr>"
'rsTest.Fields.Count - 记录集字段个数
For I = 0 To rsTest.Fields.Count - 1
'rsTest(I).Name - 第 I 个字段的字段名
Response.Write "<td>" & rsTest(I).Name & "</td>"
Next
Response.Write "</tr>"
While Not rsTest.EOF
Response.Write "<tr>"
'用循环输出每一个字段的值
For I = 0 To rsTest.Fields.Count - 1
Response.Write "<td>" & rsTest(I) & "</td>"
Next
Response.Write "</tr>"
rsTest.MoveNext
Wend
'读取下一个Recordset对象
Set rsTest = rsTest.NextRecordset
Wend
Cnn.Close
Set rsTest = Nothing: Set Cnn = Nothing
%>
说明:SQL Server数据库支持多个记录集,而Access数据库不支持。
五、 尽早关闭连接,释放资源
在以往的例子中,都是最后关闭连接,然而Connection对象要占用资源,事实上,按下面wuf65.asp所提供的方法,完全可以更早一点关闭连接。
<% @LANGUAGE = VBScript %>
<!--#include file="AdoAccess.asp"-->
<!--#include file="adovbs.inc"-->
<% ' wuf65.asp
Dim StrSQL, rsTest
StrSQL = "Select * From 运货商"
Set rsTest = server.CreateObject("ADODB.Recordset")
'一定要使用客户端游标, 否则不行
rsTest.CursorLocation = adUseClient
rsTest.Open StrSQL,Cnn,,,adCmdText
'删除记录集对 Connection 对象的依赖
Set rsTest.ActiveConnection = Nothing
'尽可能早的关闭连接
Cnn.close: Set Cnn = Nothing
Do While Not rsTest.EOF
Response.Write rsTest(0) & " " & rsTest(1) & " " & rsTest(2) & " " & "<BR>"
rsTest.MoveNext
Loop
Set rsTest = Nothing
%>
Set rsTest = Server.CreateObject("ADODB.Recordset")
'检索多个记录集
StrSQL = "Select COUNT(*) AS '雇员数' From employee; Select * From jobs"
rsTest.Open StrSQL, Cnn ', , ,adCmdText
While Not rsTest Is Nothing
Response.Write "<Table Border = 2><tr>"
'rsTest.Fields.Count - 记录集字段个数
For I = 0 To rsTest.Fields.Count - 1
'rsTest(I).Name - 第 I 个字段的字段名
Response.Write "<td>" & rsTest(I).Name & "</td>"
Next
Response.Write "</tr>"
While Not rsTest.EOF
Response.Write "<tr>"
'用循环输出每一个字段的值
For I = 0 To rsTest.Fields.Count - 1
Response.Write "<td>" & rsTest(I) & "</td>"
Next
Response.Write "</tr>"
rsTest.MoveNext
Wend
'读取下一个Recordset对象
Set rsTest = rsTest.NextRecordset
Wend
Cnn.Close
Set rsTest = Nothing: Set Cnn = Nothing
%>
说明:SQL Server数据库支持多个记录集,而Access数据库不支持。
五、 尽早关闭连接,释放资源
在以往的例子中,都是最后关闭连接,然而Connection对象要占用资源,事实上,按下面wuf65.asp所提供的方法,完全可以更早一点关闭连接。
<% @LANGUAGE = VBScript %>
<!--#include file="AdoAccess.asp"-->
<!--#include file="adovbs.inc"-->
<% ' wuf65.asp
Dim StrSQL, rsTest
StrSQL = "Select * From 运货商"
Set rsTest = server.CreateObject("ADODB.Recordset")
'一定要使用客户端游标, 否则不行
rsTest.CursorLocation = adUseClient
rsTest.Open StrSQL,Cnn,,,adCmdText
'删除记录集对 Connection 对象的依赖
Set rsTest.ActiveConnection = Nothing
'尽可能早的关闭连接
Cnn.close: Set Cnn = Nothing
Do While Not rsTest.EOF
Response.Write rsTest(0) & " " & rsTest(1) & " " & rsTest(2) & " " & "<BR>"
rsTest.MoveNext
Loop
Set rsTest = Nothing
%>