How do I control number of record fetch from database

Posted on 2009-04-27
Last Modified: 2012-05-06
I currently developed a window form application using data binding concept.
Due to there are too many records (> 50K) in the database table, it take very long to load the form.
I am looking for a solution to partially fetch the record from database.
My idea is to fetch first 100 records when form is loaded. When user navigates (using binding navigator) the record let's say until record number 90, it will automatically fetch another 100 records. Same concept applies to datagridview. If user scroll down the scrollbar of a datagrid let's say scrolling until 3/4 of the scroll area, it will automatically fetch more record and shown in the grid.

Can anyone of you guys know about how to do it?
Question by:jinhong23
    LVL 18

    Expert Comment


    You can limit the number of returned rows directly in the sql query such as:

    SELECT TOP 100 * FROM tblTable

    which would return the first 100 resulting rows from the table tblTable.


    Author Comment

    hi Carl,
    Thanks for your reply. Sorry for the ambiguous of my question.
    I have no concern on how to retrieve the first 100 records. My concern is the logic to retrieve the record based on the user event.
    E.g. When Next record button is clicked; need to check the record position to determine whether to fetch another set of record.
    When Last record button is clicked; need to sort the record in descending order and get first 100 records using and sort again using dataview sort method.

    I believe the logic/flow that I thought might be not optimized, so I would like to check if anyone have an idea or there is any the sample code.

    Also, I am using data-binding concept for CRUD. Changing or the data source query might affect the CRD functionalities. Is it advisable to create another dataset for this record navigator purpose?

    Do appreciate for any reply.

    Accepted Solution

    I found some reference from code project website

    It give me some idea to proceed.


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now