Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 26th, 2007, 07:00 PM
Friend of Wrox
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default Pull records from the database one batch at a time


I am trying to learn how to use Iterators to pull records from a database one batch at a time in a clean and reusable manner but am strugling to find any tutorials online.

I have created a simple databse with 15000 Blog Post records but do not want to bring all those records at the same time.

The problems is that I am not sure how to create the SQL statement to be able to batch groups of statements together.

How can we get a batch of records from the Database and then when we go back for the second batch how does it know what record (database row) to start from?

This is how I would simulate loading posts from the database. But this is hard coded and not from the database

static ICollection<BlogPost> GetPostBatch(int index)
List<BlogPost> posts = new List<BlogPost>();
// code to simulate loading posts from the database...
switch (index)
case 0:
posts.AddRange(new BlogPost[]
new BlogPost("First Post")
, new BlogPost("Second Post")
, new BlogPost("Third Post")

case 1:
posts.AddRange(new BlogPost[]
new BlogPost("Fourth Post")
, new BlogPost("Fifth Post")
, new BlogPost("Sixth Post")

case 2:
posts.AddRange(new BlogPost[]
new BlogPost("Seveth Post")
, new BlogPost("Eighth Post")

case 3:
//no more data to return.
return null;
return posts;

I would appreciate if someone could point me to an online tutorial or provide some sample code.



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding multiple records at the same time Vince_421 Access VBA 14 February 1st, 2007 10:28 AM
problem displaying records in order of time ,date method PHP Databases 3 July 25th, 2006 08:16 PM
Pull Records based on Dates sprocket Access 3 July 17th, 2006 03:42 PM
Diplay records from database braheem Classic ASP Databases 3 July 25th, 2005 10:08 PM
random records from database HammR PHP Databases 1 December 11th, 2003 02:03 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.