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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:20:55+00:00 2026-06-06T06:20:55+00:00

I need to query large amount of data from a database via C# and

  • 0

I need to query large amount of data from a database via C# and ADO.NET (IDbDataReader and IDbCommand API).
I’ve created a query like the follwing:

WITH v as 

(SELECT myFields, Datefield 

ROW_NUMBER() OVER (ORDER BY Datefield ASC) AS CurrentRow 

FROM dbTable 

WHERE /**/ 

AND Datefield BETWEEN @pStart AND @pEnd 

// ... )


SELECT myFields, Datefield from v where CurrentRow 
BETWEEN @pRowStart AND @pRowEnd

From the results I have to use an C# API which will transform and generate new data,
thats why an SqlServer – only solution can’t be used.

I want to query against the database with a pagesize of 10000 until there is no more data.
Something like

while (true)
{
  // ... execute reader
  if (reader.HasRows) 
     break;
}

will not work cause I have to use the IDbDataReader interface.

What can I do in my situation?

EDIT + Solution
I iterate over each block in a while loop and check HasRows property of the datareader, cause i can use the specialized type.

  • 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-06T06:20:57+00:00Added an answer on June 6, 2026 at 6:20 am

    On SQL Server 2012 you can use the OFFSET and FETCH clauses for simple and efficient paging, as shown in the ORDER BY clause examples:

    SELECT DepartmentID, Name, GroupName
    FROM HumanResources.Department
    ORDER BY DepartmentID ASC 
        OFFSET @StartingRowNumber - 1 ROWS 
        FETCH NEXT @RowCountPerPage ROWS ONLY;
    

    On previous versions you can use a CTE and ROW_NUMBER() to calculate a number for each row and limit the results:

    WITH OrdersRN AS
    (
        SELECT ROW_NUMBER() OVER(ORDER BY OrderDate, OrderID) AS RowNum
          ,OrderID
          ,OrderDate
          ,CustomerID
          ,EmployeeID
        FROM dbo.Orders
    )
    
    SELECT * 
      FROM OrdersRN
      WHERE RowNum BETWEEN (@PageNum - 1) * @PageSize + 1 
                  AND @PageNum * @PageSize
      ORDER BY OrderDate ,OrderID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm gettint a large amount of data from a database query and I'm making
You need to pull a large amount of data (thousands of entries) from a
Need to query my SQL server from Access using an ADO connection (for example),
I need to query a Sybase database which has a lot of data in
I need to find a way to efficiently process a large amount of data
I have a situation in which a large amount of data output from Matlab
I have a rather large table which I need to query for a reporting
If you had a fairly large amount of data (say a million rows) that
I am keeping a large amount of words in a database that I want
The following query returns data right away: SELECT time, value from data order by

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.