Populating a datgrid on demand

D

Dave Hutchings

Hi,
My problem is this, I have a search screen which creates a query that
performs a search on a large database. The results of this search could, if
the user requires, return many many rows (20,000).....

In other languages, when faced with this problem, you can run a query and
link it to a datasource and link the datasource to a table. You can then set
an option called packetrecords to 20. If your grid has 40 rows, then as it
populates it will cause the query to return another batch of rows from the
cursor to populate the grid . As you scroll down the grid rows are fetched
each time "on demand" until the cursor is fully returned. This means that
the entire 20,000 rows aren't retrieved from the dataset and reduces traffic
and speeds up the grid..

I cannot seem to achieve the same effect to populate a grid (at least that
easily anyway) without having to create a virtual grid and write a lot of
code.
I know using a datareader and performing a read() doesn;t return a whole
cursor at once as I have tested it using the sql profiler - so I was hoping
that someone knows the magic property i need to set to populate a gridview
this way....

regards to all

Dave.
 
G

Guest

In addition,

What I have at the moment is a listview. I open an sqlcmd and create a
datareader on it. It the listviewselectionchanged I execute the following
code...

if (e.ItemIndex == listView1.Items.Count-1)
{
for (int ctr = 0; ctr <= 10; ctr++)
{
if (allSQLObjects.Read())
{
additem(allSQLObjects["Surname"].ToString(),
allSQLObjects["Name"].ToString());
}
}
}

This causes another 10 records to be read from the cursor and the listview
grows. If you keep you finger on the down arrow - then eventually the
listview will be full.

I will also add a close() for the data reader and tidy the code up a little
more, and may do mouse down events to call this code when they scroll etc.

If anyone has a better method for doing this I would be greatful - as to
populate a grid with 20,000 records a user may not want to see will take a
while - when the chances are they will find what they are looking for if the
data is sorted correctly in the first 100 or so.. Trying to work out if a
user is going to return too many rows is not ideal - so if I can fill the
display with 10 (or 100) at a time it would be great..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top