Problem in Returning Recordset in ASP

Discussion in 'ASP General' started by vinodkus@gmail.com, Apr 14, 2007.

  1. Guest

    wrote:
    > I M BEGINNER IN ASP



    Please stop shouting.


    > I WANT TO RETURN TOTAL RECORDS FROM A TABLE.
    > THERE ARE TWO FORMS CLASS1.ASP AND CLASS2.ASP



    Total records?? I think (hope) you mean "count of the total records".
    In
    ASP, unless you have some means to limit the number of rows in a
    table, you
    should never be thinking about retrieving all the records in a table.
    Always
    use a WHERE clause to limit your results. If that is not possible, use
    the
    TOP n operator.


    > THROUGH FIRST FORM I JUST POST THE NAME OF TABLE
    > SO I M WRITING THE CODE OF CLASS2.ASP



    <snip of irrelevant html>


    > dim rs,rs1


    > class AddNum



    > public function showRecordCount()
    > tbl = Request.Form("txtTbl")
    > rs = con.execute("select count(*) from "&tbl)




    You are missing the "Set" keyword here - you are dealing with an
    object
    variable, not scalar.


    > end function



    What is this function supposed to do? Simply open the recordset and
    assign
    it to the global rs variable? If so, why use a function? A sub would
    be more
    suited for this given that you aren't returning any values from the
    procedure.


    > public function returnRS
    > tbl = Request.Form("txtTbl")
    > rs1 = con.execute("select * from "&tbl)




    Again, you are missing the "Set" keyword here - you are dealing with
    an
    object variable, not scalar.


    > end function



    Again, a function that does not return anything! This is bizarre.
    Also, the
    misguided use of selstar! ALWAYS (my turn to shoult) specify the names
    of
    the fields you wish to retrieve. http://www.aspfaq.com/show.asp?id=2096


    > end class



    > dim obj
    > set obj = new AddNum



    > obj.showRecordCount
    > Response.write("<br>")



    > Response.write ("Total Record is " & rs(0))




    <snip of irrelevant html>


    > <%
    > obj.returnRS
    > if not rs1.eof then '/*********LINE NO 66 *****************/



    <snip of irrelevant html>


    > MY ERROR IS
    > Error Type:
    > Microsoft VBScript runtime (0x800A01B6)
    > Object doesn't support this property or method: 'eof'
    > /vkasp/aspClass/class2.asp, line 66



    > BUT WHEN I COMMENT THE IF AND WHILE LOOP PROCEDURE IT GIVES THE FIRST
    > RECORD




    Really? I'm amazed. Without the Set keyword, rs1 should not even be a
    recordset. Here is how I would recode this class (I would be passing
    the
    list of field names for the select clause but I won't get into that).

    <%
    dim rs, sTbl
    sTbl=Request.Form("txtTbl") 'only access collections once


    class AddNum


    public function showRecordCount(con, tbl)
    dim rsLocal, sql
    sql="select count(*) from " & tbl
    set rsLocal= con.execute(sql,,1)
    showRecordCount = rsLocal(0)
    rsLocal.close
    end function


    public function returnRS(con, tbl)


    dim sql
    sql="select * from " & tbl
    Set returnRS = con.execute(sql,,1)
    end function


    end class


    dim obj
    set obj = new AddNum


    Response.write("<br>")


    Response.write "Total Record is " & _
    obj.showRecordCount(con,sTbl)


    Set rs = obj.returnRS(con, sTbl)
    'The IF statement is not necessary since you are not
    'doing anything (it seems) if EOF is true


    Do Until rs.EOF
    ...
    Loop
    %>


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so
    I
    don't check it very often. If you must reply off-line, then remove
    the
    "NO SPAM"

    ##############################################
    First of thanks for ur co-operation
    sir I have used ur suggested code
    but it is giving error

    Error Type:
    Response object, ASP 0104 (0x80070057)
    Operation not Allowed
    /vkasp/aspClass/class2.asp

    and no line no is given.
    please help me
    Thanks
     
    , Apr 14, 2007
    #1
    1. Advertising

  2. wrote:
    > wrote:
    >> I M BEGINNER IN ASP

    >


    please trim text that is not relevant to your reply

    <trim>
    > First of thanks for ur co-operation
    > sir I have used ur suggested code
    > but it is giving error
    >
    > Error Type:
    > Response object, ASP 0104 (0x80070057)
    > Operation not Allowed
    > /vkasp/aspClass/class2.asp
    >
    > and no line no is given.
    > please help me


    You are going to have to determine the guilty line of code by commenting
    statements until the code runs without error. Then tell us which line of
    code causes the problem.


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Apr 14, 2007
    #2
    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. Developer
    Replies:
    0
    Views:
    485
    Developer
    Aug 11, 2003
  2. =?Utf-8?B?cGF0cmlja2RyZA==?=

    webservice returning dataset (recordset) to visual basic 6 app?

    =?Utf-8?B?cGF0cmlja2RyZA==?=, May 6, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    689
    John Timney \(MVP\)
    May 6, 2007
  3. Hung Huynh
    Replies:
    8
    Views:
    311
    Bob Barrows
    Sep 24, 2003
  4. Eli Sidwell

    Returning RecordSet to ASP is empty

    Eli Sidwell, Feb 10, 2004, in forum: ASP General
    Replies:
    4
    Views:
    214
    Eli Sidwell
    Feb 11, 2004
  5. Replies:
    1
    Views:
    133
    Bob Barrows [MVP]
    Apr 12, 2007
Loading...

Share This Page