Problem: Using GetRows()

Objective: to get the recordset into an array

Got a wierd problem with using GetRows.

<%
' Connection Strings have been set

set rs = Server.CreateObject("ADODB.recordset")
SQL = "SELECT TeamName FROM teams"
rs.Open SQL, conn

dim arrTeams
arrTeams = rs.GetRows()

response.write Ubound(arrTeams) & "<br>"
%>
returns:
0

<%
for each z in arrTeams
      response.write z & "<br>"
next
%>
returns the following:
Rockets
Knicks
Lakers
Jazz
Hawks
Clippers


How can i get the recordset into an array so that I can reference it as arrTeams(0) ... arrTeams(Ubound(arrTeams))

:) SD
LVL 11
sciber_dudeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fritz_the_blankCommented:
Here is how I do it:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<%
dim strDataPath, objConnection
strDataPath = SErver.MapPath("family.mdb")
set objConnection=Server.CreateObject("ADODB.Connection")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
       + " Data Source= " & strDataPath & ";"_
       + " Mode=Share Deny None;User Id=admin;PASSWORD=;"

objConnection.ConnectionTimeout = 15
objConnection.CommandTimeout =  10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
  objConnection.Open strConnectString
end if

dim strSQL, objRS

strSQL= "SELECT * FROM Person"
set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL,objConnection,3,3


Response.Write("Let's start with doing it the recordset way:<p>")
Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
for i=1 to objRS.RecordCount
      Response.Write("<TR>")
      for j=0 to objRS.Fields.count-1
            Response.Write("<TD>" & objRS(j).Value & "</TD>")
      next
      Response.Write("</TR>")
      objRS.MoveNext
next
Response.Write("</Table>")

Response.Write("<p>Now let's use the getRows() method:<p>")
objRS.MoveFirst
arrRows=objRS.GetRows()
Response.Write("<P>Colmn Index (starts at 0): " & UBound(arrRows,1)) ' Reads left to right
Response.Write("<br>Row Index (starts at 0): " & UBound(arrRows,2) & "<P>") ' Reads up to down

Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
for i=0 to UBound(arrRows,2)
      Response.Write("<TR>")
      for j=0 to UBound(arrRows,1)
            Response.Write("<TD>" & arrRows(j,i) & "</TD>")
      next
      Response.Write("</TR>")
next
Response.Write("</Table>")
objRS.Close
set objRS = Nothing
objConnection.close
set objConnection = Nothing

%>
</BODY>
</HTML>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fritz_the_blankCommented:
I have two tables here--the first being the typical way that you would iterate through the recordset, the second  using the GetRows() method.

FtB
0
sciber_dudeAuthor Commented:
Thanks FtB,

this was the first time i was trying the getrows method and i ran into problems. I will test this code in a few min and close this question.

Thank you,
:) SD
0
sciber_dudeAuthor Commented:
Thanks FtB, it works like a charm

:) SD
0
fritz_the_blankCommented:
Glad to have helped,

FtB
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.