By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Populating a datgrid on demand

P: n/a
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.
Jul 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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..
--
regards
Dave Hutchings
"Dave Hutchings" wrote:
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.
Aug 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.