GetRows

Discussion in 'ASP General' started by shank, Mar 13, 2008.

  1. shank

    shank Guest

    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>
     
    shank, Mar 13, 2008
    #1
    1. Advertising

  2. 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.
     
    Bob Barrows [MVP], Mar 13, 2008
    #2
    1. Advertising

  3. shank

    shank Guest

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

    "Bob Barrows [MVP]" <> wrote in message
    news:%...
    > 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.
    >
    >
     
    shank, Mar 13, 2008
    #3
  4. shank

    daddywhite Guest

    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?
     
    daddywhite, Mar 13, 2008
    #4
  5. 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.
     
    Bob Barrows [MVP], Mar 13, 2008
    #5
  6. daddywhite wrote:
    > 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? :)

    --
    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.
     
    Bob Barrows [MVP], Mar 13, 2008
    #6
  7. shank

    shank Guest

    There was no error. Just an empty screen.
    thanks

    "Bob Barrows [MVP]" <> wrote in message
    news:%...
    > 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.
    >
    >
     
    shank, Mar 13, 2008
    #7
  8. shank

    shank Guest

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


    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > daddywhite wrote:
    >> 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? :)
    >
    > --
    > 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.
    >
    >
     
    shank, Mar 13, 2008
    #8
  9. Then you must have had "on error resume next" masking the error.

    shank wrote:
    > There was no error. Just an empty screen.
    > thanks
    >
    > "Bob Barrows [MVP]" <> wrote in message
    > news:%...
    >> 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.


    --
    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.
     
    Bob Barrows [MVP], Mar 13, 2008
    #9
  10. shank

    daddywhite Guest

    > 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
     
    daddywhite, Mar 13, 2008
    #10
  11. shank

    shank Guest

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

    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > Then you must have had "on error resume next" masking the error.
    >
    > shank wrote:
    >> There was no error. Just an empty screen.
    >> thanks
    >>
    >> "Bob Barrows [MVP]" <> wrote in message
    >> news:%...
    >>> 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.

    >
    > --
    > 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.
    >
    >
     
    shank, Mar 13, 2008
    #11
  12. daddywhite wrote:
    >> 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


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

    --
    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.
     
    Bob Barrows [MVP], Mar 14, 2008
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Croney69

    Using GetRows()

    Croney69, Jul 28, 2003, in forum: ASP General
    Replies:
    5
    Views:
    183
    Bob Barrows
    Jul 28, 2003
  2. Moshe

    GetRows Mystery

    Moshe, Aug 28, 2003, in forum: ASP General
    Replies:
    8
    Views:
    150
    Bob Barrows
    Aug 28, 2003
  3. Crane Linkledder

    Difference between getrows and getstring

    Crane Linkledder, Oct 29, 2003, in forum: ASP General
    Replies:
    11
    Views:
    280
    Aaron Bertrand - MVP
    Oct 30, 2003
  4. Jim

    GetRows Random <td></td> Output

    Jim, Nov 21, 2003, in forum: ASP General
    Replies:
    1
    Views:
    117
    Jeff Clark
    Nov 22, 2003
  5. Harag

    JScript & GetRows

    Harag, Dec 27, 2003, in forum: ASP General
    Replies:
    4
    Views:
    217
    The Mighty Chaffinch
    Dec 28, 2003
Loading...

Share This Page