Click to See Complete Forum and Search --> : dataset table


Nasty2
September 9th, 2005, 03:47 AM
hey,

im working on 2 applications (one is a Web application and the other is a Windows Application) and got the same problem in both!!
I am retreiving information (quite a chunk) from a database using a DataReader...... but on the form I need buttons to move to the Previous, Next, Last and First records! (can't move backwards with a DataReader right?)
What would be the best practice to solve this problem?...... Should I not use a DataReader and use a DataSet and Table instead? (Would i be able to move through the records then?)

thanks

jmcilhinney
September 9th, 2005, 05:00 AM
If you want to move backwards in the result set then you must store the data somewhere locally. You can use a DataAdapter to Fill a DataTable, or you can still use a DataReader. With a DataReader you would either have to retrieve all the data first and then use it, or store each row when you move onto the next so that you can then navigate back to previous rows. The DataAdapter is the easiest option, while using the DataReader in the first scenario is faster but needs a little more code. You can call GetSchemaTable on a DataReader to generate an empty DataTable with the correct schema already applied. The third scenario might be preferable if you will have a large result set but might only want a small number of the early rows. It would be fiddly to implement and would keep your connection open the longest, so I'd avoid that unless you need it.