Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6589635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:11:58+00:00 2026-05-25T17:11:58+00:00

Right now the code is (to keep things simple I didn’t use the ADO

  • 0

Right now the code is (to keep things simple I didn’t use the ADO Command Object yet to prevent SQL injection).

I have a large dataset. I’m using getrows method which is awesome to retrieve the recordsets. I can’t find a similar stored procedure to retrieve records based on which page you are own within the browser.

Basically the sql retrieves 10 recordsets relative to the page the clients browser is on. It gets the page value from the CurrPage value. I handle the first page and last page with server side code so there arent any errors.

Any help is appreciated.

If IsEmpty(Request.Querystring("pg")) then
CurrPage = 1
Else
CurrPage = Cint(Request.Querystring("pg"))
End If

RSPrevPage = CurrPage -1
RSNextPage = CurrPage + 1 

SQL = "SELECT gallerypublic.img, gallerypublic.galleryID, blahblahblah FROM gallerypublic INNER JOIN GalleryPublicCat ON gallerypublic.publicgallerycatid = GalleryPublicCat.pubcatID INNER JOIN userbase ON gallerypublic.userid = userbase.userid Order by galleryid desc"

Set rsFeed = Server.CreateObject("ADODB.Recordset")
rsFeed.Open sql, Conn, adOpenKeyset, adLockReadOnly
rsFeed.PageSize = 10
rsFeed.AbsolutePage = CurrPage
arrFeed = rsFeed.getrows(10)
intPageCount = rsFeed.PageCount
rsFeed.close
set rsFeed = Nothing

I found this stored procedure on http://www.aspfaqs.com/webtech/042606-1.shtml but I can’t translate it to my needs.

TIA

After a little trial and error, here’s the working code:

Server Side:

    If IsEmpty(Request.Querystring("pg")) then
    CurrPage = 1
    Else
    CurrPage = Cint(Request.Querystring("pg"))
    End If

    RSPrevPage = CurrPage -1
    RSNextPage = CurrPage + 1

    pgSize = 10

    Set objCommandSec = CreateObject("ADODB.Command") 
    objCommandSec.ActiveConnection = Conn

    With objCommandSec
    Set .ActiveConnection = Conn
    .CommandType = adCmdStoredProc
    .CommandText = "spPageDef"
    .Parameters.Append .CreateParameter("@PageNum", 200, 1, 255, CurrPage)
    .Parameters.Append .CreateParameter("@PageSize", 200, 1, 255, pgSize)
    .Parameters.Append .CreateParameter("@TotalRowsNum", adInteger, adParamReturnValue)

    Set rsFeed = objCommandSec.Execute
    arrFeed = rsFeed.getrows()
    rsFeed.close
    set rsFeed = nothing

    intPageCount = cLng((.Parameters(2).value/pgSize))

    End With

Stored Procedure:

    @PageNum int,
    @PageSize int,
    @TotalRowsNum int output

    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from

        -- interfering with SELECT statements.

        SET NOCOUNT ON;

        -- Use ROW_NUMBER function

        WITH DefaultEntries As
        (
            SELECT  
g.img, g.galleryID, g.viewed, g.votes, g.rate, g.created, blahblah,
'RowNumber' = ROW_NUMBER() OVER(ORDER BY galleryid DESC)

        FROM gallerypublic AS g INNER JOIN GalleryPublicCat AS gpc ON g.publicgallerycatid = gpc.pubcatID INNER JOIN userbase AS u ON g.userid = u.userid
        )

        -- Query result

        SELECT * 
        FROM DefaultEntries
        WHERE RowNumber BETWEEN (@PageNum - 1) * @PageSize + 1 AND @PageNum * @PageSize             
        ORDER BY galleryid DESC

    SELECT @TotalRowsNum = count(galleryid) 
    FROM gallerypublic AS g INNER JOIN GalleryPublicCat AS gpc ON g.publicgallerycatid = gpc.pubcatID INNER JOIN userbase AS u ON g.userid = u.userid

    END

Thanks to all who helped out and pointed me in the correct direction

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:11:58+00:00Added an answer on May 25, 2026 at 5:11 pm

    Stored Procedure

        @PageNum int,
        @PageSize int,
        @TotalRowsNum int output
    
        BEGIN
            -- SET NOCOUNT ON added to prevent extra result sets from
    
            -- interfering with SELECT statements.
    
            SET NOCOUNT ON;
    
            -- Use ROW_NUMBER function
    
            WITH DefaultEntries As
            (
                SELECT  
    g.img, g.galleryID, g.viewed, g.votes, g.rate, g.created, blahblah,
    'RowNumber' = ROW_NUMBER() OVER(ORDER BY galleryid DESC)
    
            FROM gallerypublic AS g INNER JOIN GalleryPublicCat AS gpc ON g.publicgallerycatid = gpc.pubcatID INNER JOIN userbase AS u ON g.userid = u.userid
            )
    
            -- Query result
    
            SELECT * 
            FROM DefaultEntries
            WHERE RowNumber BETWEEN (@PageNum - 1) * @PageSize + 1 AND @PageNum * @PageSize             
            ORDER BY galleryid DESC
    
        SELECT @TotalRowsNum = count(galleryid) 
        FROM gallerypublic AS g INNER JOIN GalleryPublicCat AS gpc ON g.publicgallerycatid = gpc.pubcatID INNER JOIN userbase AS u ON g.userid = u.userid
    
        END
    

    Server Side

    If IsEmpty(Request.Querystring("pg")) then
    CurrPage = 1
    Else
    CurrPage = Cint(Request.Querystring("pg"))
    End If
    
    RSPrevPage = CurrPage -1
    RSNextPage = CurrPage + 1
    
    pgSize = 10
    
    Set objCommandSec = CreateObject("ADODB.Command") 
    objCommandSec.ActiveConnection = Conn
    
    With objCommandSec
    Set .ActiveConnection = Conn
    .CommandType = adCmdStoredProc
    .CommandText = "spPageDef"
    .Parameters.Append .CreateParameter("@PageNum", 200, 1, 255, CurrPage)
    .Parameters.Append .CreateParameter("@PageSize", 200, 1, 255, pgSize)
    .Parameters.Append .CreateParameter("@TotalRowsNum", adInteger, adParamReturnValue)
    
    Set rsFeed = objCommandSec.Execute
    arrFeed = rsFeed.getrows()
    rsFeed.close
    set rsFeed = nothing
    
    intPageCount = cLng((.Parameters(2).value/pgSize))
    
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I have this code where $obj_arr maybe contain array and an object.
Right now my code works as such: def method_a self.method_b ==> 'method_b' end def
I have some code right now that executes when a link is clicked. The
I have this code right now to get the row value from jquery grid..
Right now i have a line of code, in vb, that calls a text
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
right now i am simply ftping everything (all of my source code included) but
right now, i code custom wordpress theme and testing it in xampp windows XP
I have an odd edge case right now in that a response code from
I'm currently doing something like this in some code I'm working on right now:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.