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 8052093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:27:45+00:00 2026-06-05T07:27:45+00:00

I have the following code which executes a custom query to the database. The

  • 0

I have the following code which executes a custom query to the database.
The queries definition is stored on a table, but the users wont enter pagination.

Because it can return 10,000 rows or more I need to paginate by modifying the query.

QuerySql= “select * from requestbases where currentstatus == ‘Approved
1’ and ammountwithvat>100000”

It returns 10,000 rows.

My code:

 public DataTable GetGenericResults(string strsql)
            {
                using(var connection = (SqlConnection)_context.Database.Connection)
                {
                    var adapter = new SqlDataAdapter(strsql, connection);
                    var results = new DataSet();
                    adapter.Fill(results, "Results");
                    return results.Tables["Results"];
                }
            }




var datatable = RequestBaseBL.GetGenericResults(query.QuerySql);
                    if (datatable.Rows.Count > 0)
                    {
                        LblCount.Text = datatable.Rows.Count + " records";
                        PanelResults.Visible = true;
                        GrvCustomResults.Visible = true;
                        GrvCustomResults.DataSource = datatable;
                        GrvCustomResults.DataBind();
  • 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-06-05T07:27:46+00:00Added an answer on June 5, 2026 at 7:27 am

    I would use the query in a CTE, like this

    WITH MyPagedData as (
    SELECT *,
    ROW_NUMBER() OVER(ORDER BY IdentityCol DESC) as RowNum,
    ROW_NUMBER() OVER(ORDER BY IdentityCol ASC) as InverseRowNum
    FROM requestbases where currentstatus == 'Approved 1' and ammountwithvat > 100000
    )
    
    SELECT * from MyPagedData where RowNum between @StartIndex and @StartIndex + 20  
    

    So this assumes that you are able to write some code that inserts the RowNumber bit in the right place of the select statement and also that you are using MSSQL 2005. You may also need to adjust the IdentityCol bit if you haven’t got identity columns.

    So StartIndex is the last shown item of data and 20 is the amount of items you want on a page. The total amount of items is the sum of RowNum and InverseRowNum -1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code which works for radio buttons but need to be changed
I have the following code which is meant to access the local database and
I have following code, which executes on button press. At first it works as
I have the following code in my Ajax, which executes a page reload function
I have the following code that executes a query and writes it directly to
In C# I can use the following code to have code which only executes
I have the following code in one of my Sql (2008) Stored Procs which
I have php code which executes a loop, inside which it generates the following:
I want to know is below code correct ? I have following code which
i have the following code which works fine to download image form url .

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.