Fill dataset incrementally

  • Thread starter Thread starter Abra
  • Start date Start date
A

Abra

Is it possible to fill a ADO.NET dataset incrementally ? (I mean to call
the DataAdapter Fill() method several times, as I did not found a Add()
method)
I would like to call in a background thread the Fill method several
times, only with a limited number of records, as I have very many
records in the database. The dataset is attached to a control (listbox)
and I would like that the listbox appears quickly on screen with some 50
records (for more than that the user has to scroll anyway) and fill it
later further in background. Do I have to deassign the dataset from the
listbox before actualizing it (by calling the Fill method), and reassign
it after that ? Would be better to use for the subsequent database
fetches a new dataset that I merge each time to the "main" dataset, that
is attached to the listbox ? Or is there any better way to achieve this
behaviour ?
Thanks in advance.
Regards,
Abra
 
Yes, you can call fill any number of times you want. The catch is that if
you call Fill with the exact same query on a Keyed datatable, then you'll
violate a constraint and it will blow up. HOwever if you specified the
first 10 records in your where caluse, then specified the next 10, then the
next 10 etc, you're fine. As well, if you choose records that don't violate
any constriants, you're good to go.

Cheers,

Bill
 
Hi,

And one more catch - there is no simple way to say select first 10 records,
then select next 10 records. This is a paging issue and this issue is pretty
known and there is no simple solution to it. SQL Server 2005 introduces this
functionality.

--
Val Mazur
Microsoft MVP

http://xport.mvps.org
 
Thank you for your answers.
I tried to implement it, but my application crashes (some Windows.Forms
Null reference exception) wenn I call Fill the second time, from the
task that I created. It could be that there is a problem to change the
dataset that is already linked to the listbox. On the other hand, there
is no Invoke() function available for ADO.NET classes ... I will
probably have to define a timer event in the form, and call from there
the Fill() method, hope that it will work ...
To select first 10 records and the next 10 I was thinking to use the
LIMIT key in the SQL query (LIMIT 0, 10, and then LIMIT 10, 20, and so
on), I hope it is supported also by MySQL.
Regards,
Abra
 
Back
Top