GetRows() Demo

This demo illustrates how to turn a Recordset into a two-dimensional array using the GetRows() method of the Recordset object. Note that once we have the Recordset in an array form, we can close our Recordset and Connection objects and display the information from the array.


A Display of the Recordset as an Array

181
How can I format numbers and date/times using ASP.NET? For example, I want to format a number as a currency.
964702
22
Scott Mitchell
mitchell@4guysfromrolla.com
1/19/2002 3:12:07 PM
ASP.NET


161
How can I convert a Recordset into an array? Also, how can I convert an array into a Recordset?
238089
1
Scott Mitchell
mitchell@4guysfromrolla.com
6/14/2001 5:02:03 PM
Arrays


115
I am using Access and getting a 80004005 error (or a [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)' error) when trying to open a connection! How can I fix this problem?
233530
21
Scott Mitchell
mitchell@4guysfromrolla.com
1/17/2001 11:38:49 PM
Databases, Errors


83
How can I quickly sort a VBScript array?
230033
1
Richard Lowe
chadich@yahoo.com
11/12/2000 1:58:42 AM
Arrays


190
How do I display data on a web page using arrays instead of Do...While...MoveNext...???...
186006
1
Scott Mitchell
mitchell@4guysfromrolla.com
4/11/2002 1:14:41 PM
Arrays


106
How can I find out if a record already exists in a database? If it doesn't, I want to add it.
183511
12
Steve Cimino
steve_cimino@hotmail.com
12/14/2000 4:59:12 PM
Databases, Queries


118
When I get a list of all files in a directory via the FileSystemObject, they aren't ordered in any reasonable way. How can I sort the files by name? Or by size? Or by date created? Or...
168750
4
Bill Wilkinson
bill@ClearviewDesign.com
1/22/2001 5:10:02 PM
FileSystemObject


30
For session variables to work, must the Web visitor have cookies enabled?
133635
6
Scott Mitchell
mitchell@4guysfromrolla.com
9/26/2000 11:13:06 PM
Session Object


14
Can I send emails without using CDONTS?
130322
10
Scott Mitchell
mitchell@4guysfromrolla.com
9/24/2000 1:18:38 AM
Email


149
How can I remove multiple spaces between words in a string? That is, if I have: Hi    there how can I get: Hi there?
129557
2
Scott Mitchell
mitchell@4guysfromrolla.com
3/31/2001 5:02:55 PM
Strings


A Display of the aFAQIDs Array

This shows a listing of the FAQIDs and their ViewCounts

181
964702


161
238089


115
233530


83
230033


190
186006


106
183511


118
168750


30
133635


14
130322


149
129557



Source Code
<%
  Const adOpenStatic = 3
  Const adLockReadOnly = 1

  'Establish database connection
  Dim objRS, objConn
  
  Set objConn = Server.CreateObject("ADODB.Connection")
  objConn.Open "DSN=MyDSN"
  
  'Retrieve the results of the sp_popularity stored procedure, which
  'returns the 10 most popular ASP FAQs
  '(We use a Static cursor so we can use MoveFirst... only required if you plan on
  'using multiple calls to GetRows())
  Set objRS = Server.CreateObject("ADODB.Recordset")
  objRS.Open "sp_Popularity", objConn, adOpenStatic, adLockReadOnly
  
  'Create our arrays
  Dim aPopularFAQs, aFAQIDs
  
  'Convert the array into a two-dimensional array
  aPopularFAQs = objRS.GetRows()
  
  'Move to the beginning of the Recordset, since we want to
  'call GetRows() again
  objRS.MoveFirst
  
  'Get a 2d array of the Recordset, but only for the
  'Rows FAQID and ViewCount
  aFAQIDs = objRS.GetRows(,,Array("FAQID", "ViewCount"))

  'Close our Recordset and database connection...
  objRS.Close
  Set objRS = Nothing
  
  objConn.Close
  Set objConn = Nothing
  

  'Display our two arrays...
  Response.Write("<h2>A Display of the Recordset as an Array</h2>")
  Dim iRowLoop, iColLoop
  For iRowLoop = 0 to UBound(aPopularFAQs, 2)
   
    For iColLoop = 0 to UBound(aPopularFAQs, 1)
	
	  Response.Write(aPopularFAQs(iColLoop, iRowLoop) & "<br>")
	  
	Next 'iColLoop
	
	Response.Write("<p><hr><p>")

  Next 'iRowLoop

  Response.Write("<h2>A Display of the <code>aFAQIDs</code> " & _
                 "Array</h2><i>This shows a listing of the FAQIDs and " & _
                 "their ViewCounts</i><p>")
  'Display the FAQIDs array
  For iRowLoop = 0 to UBound(aFAQIDs, 2)
   
    For iColLoop = 0 to UBound(aFAQIDs, 1)
	
	  Response.Write(aFAQIDs(iColLoop, iRowLoop) & "<br>")
	  
	Next 'iColLoop
	
	Response.Write("<p><hr><p>")

  Next 'iRowLoop
%>


[Back to the FAQ]