I'd spin it off into another thread (which is a good idea for all db access
if you are doing it in the same thread as the UI), put up a wait box of some
sort and go from there. You can break it into smaller queries but that's
going to slow the process overall in many instances, then again, there are a
lot of possible variables.
1) Is the query taking forever b/c it's huge (ie 10000 records) or is it b/c
it just takes a long time on the server? It it's b/c it's 10000 records,
then you may benefit from breaking it up
2) The user many not need all of that data since the grid only displays
less than 50 records at a time in most UI Scenarios. You may want to wait
for the user to scrolll down or something before getting the additional data
3) You should bind the grid to the table only once. If you clear it, then
it will appear to clear itself.If you fill it it will automatically show the
data.. In doing so you could keep filling the table with additional queries
However you are either going to freeze the ui or you'll need to synclock the
grid (you don't want multiple threads accessing the datatable without
locking it) it which will impede the effect you want.
4) What in the world is causing a query that long? That's the biggest
problem. If it's sheer number of records, then you are without a doubt
dealing with more data than the user is going to need at once. If you want
to pull 10000 records or slow, you can't expect to have a speed demon
(nothing magic about 10,000, my point is merely really large record counts.)
If the querry is taking that long to process on the server, you'll want to
figure out why and address this. Unless it's serious batch processing or
something, that's a LONG time for a query to run considering most take about
a second at most. I'd tune this up and get it running as fast as possible.
Even if you did 500 at a time, assuming that the size is the problem, you
could show the 500, then, if the user scrolls to a point that you need more
or hits a navigate button indicating more are needed, you could throw up a
wait box, grab another 500 (calling Datadapter.Fill(datatable) without clear
will append the records to the end which is what you want). Since you have
much smaller records this should be fast and a wait box should be tolerable.
You can do this until the table is filled.
The point if it's huge is that it's doubtful the user is going to use 10k
records in one immediate sitting. The phone might ring, a meeting may come
up or whatever. So anything more than he needed is wasted.
I think if you use threading correctly you can make the UI much more
responsive and they can do something else while the grid is filling. And if
you don't rebind it each time, just call .Fill on the table that the grid is
already bound to, you should be able to make this manageable.
HTH,
Bill
--
W.G. Ryan, eMVP
http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp