GetRows

S

shank

Trying to learn and use GetRows.
I'm using the example on: http://www.aspdev.org/articles/asp-getrows/

Without GetRows(), the below recordset will return 100+ manufacturer names.
With GetRows(), I get nothing.
What am I missing?
thanks

<%
Dim rsManuf
Dim rsManuf_numRows

Set rsManuf = Server.CreateObject("ADODB.Recordset")
rsManuf.ActiveConnection = ConnectString
rsManuf.Source = "{call stp_Manuf}"
rsManuf.CursorType = 0
rsManuf.CursorLocation = 2
rsManuf.LockType = 1
rsManuf.Open()

rsManuf_numRows = 0

If Not rsManuf.EOF Then
' Gets all the records
arrResultSet = rsManuf.GetRows()
End If
%>
<%
rsManuf.Close()
Set rsManuf = Nothing
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<%
' Retrieve the total # of rows
iRowNumber = ubound(arrResultSet,2)

' Loop through the array holding the result set and display the data
For iCounter= 0 to iRowNumber
Response.Write(arrResultSet(1,iCounter) & "")
Next
%>
</body>
</html>
 
B

Bob Barrows [MVP]

shank said:
Trying to learn and use GetRows.
I'm using the example on: http://www.aspdev.org/articles/asp-getrows/

Without GetRows(), the below recordset will return 100+ manufacturer
names. With GetRows(), I get nothing.
What am I missing?

Without being able to run this against your database I'm not sure how we
can answer this. But let's see ...
thanks

<%
Dim rsManuf
Dim rsManuf_numRows

Set rsManuf = Server.CreateObject("ADODB.Recordset")
rsManuf.ActiveConnection = ConnectString

Nothing to do with your problem but ...
Extremely Bad Practice. Get out of the habit of doing this now. Always
open an explicit connection object and use that object to interact with
the database. Never assign a connection string to an object's
ActiveConnection property: it defeats the purpose of connection pooling:

dim cn
set cn=createobject("adodb.connection")
cn.open connectstring

rsManuf.Source = "{call stp_Manuf}"
rsManuf.CursorType = 0
rsManuf.CursorLocation = 2
rsManuf.LockType = 1
rsManuf.Open()

You are going to an awful lot of trouble to open a recordset with the
default properties. All of the above tasks can be achieved with two
lines:

Set rsManuf = Server.CreateObject("ADODB.Recordset")
cn.stp_Manuf rsManuf

rsManuf_numRows = 0

? Not much point to this line of code
If Not rsManuf.EOF Then
' Gets all the records
arrResultSet = rsManuf.GetRows()
End If
%>
<%
rsManuf.Close()
Set rsManuf = Nothing

cn.close:set cn=nothing

' Retrieve the total # of rows

You should check to see if arrResultSet is an array before attempting to
pass it to the UBound function:

If not IsArray(arrResultSet) then
Response.Write "No data was retrieved"
else

if it is array, then EOF was not true and your array should contain the
records returned by stp_Manuf.
You did not say if you got an error when calling UBound, so i suspect
your array actually did contain data.
iRowNumber = ubound(arrResultSet,2)

' Loop through the array holding the result set and display the data
For iCounter= 0 to iRowNumber
Response.Write(arrResultSet(1,iCounter) & "")

How many fields were returned by stp_Manuf? Don't forget arrays are
zero-bounded: the 1 in your statement will refer to the second field in
the resultset, not the first (if that was what you intended).

I see nothing that should have prevented the code from working, even
with the poor coding practices. Without being able to test this against
your database, I do not see how we can help.
 
S

shank

Response.Write(arrResultSet(1,iCounter) & "")<<
That was the problem,
Should have been...
Response.Write(arrResultSet(0,iCounter) & "")
thanks!
 
D

daddywhite

The code that shank showed was auto produced by dreamweaver 8 - maybe
Bob could re-write that code according to "best practice" with
comments and we can compare?
 
B

Bob Barrows [MVP]

shank said:
That was the problem,
Should have been...
Response.Write(arrResultSet(0,iCounter) & "")


And, fo future reference, if you had provided an error message and
indicated which line threw the error, it would have been a much simpler
diagnosis.
 
B

Bob Barrows [MVP]

daddywhite said:
The code that shank showed was auto produced by dreamweaver 8 - maybe

Really? I didn't see any of those mm_ variables. How did you determine
this?
Bob could re-write that code according to "best practice" with
comments and we can compare?

Well, isn't that what I just did? You want me to do it again? :)
 
S

shank

There was no error. Just an empty screen.
thanks

Bob Barrows said:
And, fo future reference, if you had provided an error message and
indicated which line threw the error, it would have been a much simpler
diagnosis.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
 
S

shank

It was generated by DW, but I usually change the MM variables to something
else. Habit I guess...
 
D

daddywhite

Really? I didn't see any of those mm_ variables. How did you determine
this?

the layout of the variables and the pointlessness of rsManuf_numRows =
0 was classic DW.
Well, isn't that what I just did? You want me to do it again? :)

Just thought it would be handy to see your interpretation of best
practice for the code all as one chunk thats all.

regards
 
S

shank

on error resume next<<
Again, you are correct. I have it inside an include file and ignored the
possibility of its presence.
sorry!
 
B

Bob Barrows [MVP]

daddywhite said:
Just thought it would be handy to see your interpretation of best
practice for the code all as one chunk thats all.

regards

OK ..

<%
dim cn, rs, arData, i
set cn=createobject("adodb.connection")
on error resume next
cn.open connectstring
if err<>0 then
'handle the error - notify user, destroy cn object
on error goto 0
else
Set rs = CreateObject("ADODB.Recordset")
cn.stp_Manuf rs
if err<> 0 then
'handle the error - notify user, close&destroy cn object
on error goto 0
else
on error goto 0
if not rs.eof then arData = rs.GetRows
rs.close: set rs=nothing
cn.close: set cn=nothing
if IsArray(arData) then
for i = 0 to ubound(arData,2)
Response.Write arData(0,i) & "<br>"
next
else
Response.Write "No records returned"
end if
end if
end if
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top