From: shank on
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>


From: Bob Barrows [MVP] on
shank wrote:
> 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

<snip irrelevant stuff>

> ' 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).

> Next

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.

--
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.


From: shank on
>>Response.Write(arrResultSet(1,iCounter) & "")<<
That was the problem,
Should have been...
Response.Write(arrResultSet(0,iCounter) & "")
thanks!

"Bob Barrows [MVP]" <reb01501(a)NOyahoo.SPAMcom> wrote in message
news:%23FhmvlThIHA.4844(a)TK2MSFTNGP06.phx.gbl...
> shank wrote:
>> 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
>
> <snip irrelevant stuff>
>
>> ' 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).
>
>> Next
>
> 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.
>
> --
> 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.
>
>


From: daddywhite on
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?
From: Bob Barrows [MVP] on
shank wrote:
>>> Response.Write(arrResultSet(1,iCounter) & "")<<
> 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.
--
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.