The
GetRows method is used to retrieve a recordset into a 2 dimensional array. For really large recordsets this is the way to go. It is
much faster than looping through the recordset.
GetRows' basic syntax is:
variable = Recordset.GetRows([Rows] , [Start] , [Fields])
The parameters are optional, meaning if you don't pass any parameters
variable = RS.GetRows() then all fields are stored in the array.
- Rows : number of rows inserted into the array.
- Start : think of it as a bookmark. this is the beginning row. default is the first row.
- Fields : used to specify a field name.
Code:
<%@ Language=VBScript %>
<%
Dim MyArray, MyConn, RS, i
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "Provider=SQLOLEDB;Data Source= NS3.domain.net;UID=username;PWD=password;DATABASE= demo.mdb"
SQL = "Select col1, col2, col3, col4 From tblCustomers"
Set RS = MyConn.Execute(SQL)
'Insert the data into the array
MyArray=RS.GetRows
'clean up
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
'Now loop through the array (much faster than looping through a recordset) and display the contents of the array
For i=0 to UBound(MyArray,2)
Response.Write "First Column = " & MyArray(0,i) & "<br>"
Response.Write "Second Column = " & MyArray(1,i) & "<br>"
Response.Write "Third Column = " & MyArray(2,i) & "<br>"
Response.Write "Fourth Column = " & MyArray(3,i) & "<p>"
Next
%>
Only one drawback: you won't be allowed to use the RecordSet features, such as .UpDate, .Delete, etc... However, and most importantly, this is a great way to display pure data. And it is
SO much faster!