?
Solved

Problem: Using GetRows()

Posted on 2004-11-18
5
Medium Priority
?
344 Views
Last Modified: 2008-03-04
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
0
Comment
Question by:sciber_dude
  • 3
  • 2
5 Comments
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 2000 total points
ID: 12620943
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12620946
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
 
LVL 11

Author Comment

by:sciber_dude
ID: 12621810
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
 
LVL 11

Author Comment

by:sciber_dude
ID: 12622004
Thanks FtB, it works like a charm

:) SD
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12625433
Glad to have helped,

FtB
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question