I have created a basic form that uses the background worker to execute a SQL query.
First I start my Background Worker which creates a DataReader(using my connection and command text), I then loop through the reader getting each row adding them to a DataTable. I use the ReportProgress method to update my screen with the current row count (this updates a label). On completion of the worker I fill a DataGridView with the Datatable.
The first time I ran a query using this method it ran very quickly(how it should work). The problem is when I run this again the DataReader appears to get the data significantly slower.
I have managed to successfully use a DataAdaptor to fill a DataTable directly(using a background worker) however I have no control over the retrieval of this data i.e I can’t cancel the executing query because it gets all the data at once.
Ideally I want to use the background worker to get data (row by row) using a DataReader, I will then store a collection of rows (in a DataTable or arraylist) this would then update my DataGridView using ReportProgress (report progress should run every 1000 rows), so every 1000 rows retrieved they will be added to the DataGridView.
For some reason my problem has only arisen when I started to use a DataReader. Is a Background Worker an appropriate way of achieving my goal
Any help would be appreciated, if you need to view my code I can post it here for you.
Many Thanks,
Andy
Visual C#14
|