DataBinding to large tables

I have a Windows Forms application with a form that has controls bound to a table with a large number of rows. Just populating a table with the primary key takes 10 seconds or so and uses a lot of memory on the client machine. Is there a "Best Practice" way of just reading in what I need instead of populating my DataTable with all rows from the backend data source? Thanks.
Paracom_IncAsked:
Who is Participating?
 
BirdbusterCommented:
Why don't you use a default value to get a default row to start with and then
just use a hashTable with a Previous value and Current value.
 If you are going to do this you may have to redo you SELECT statements to something like these.


Use This query to pouplate your DataTable

SELECT *
FROM tblProducts
WHERE Pro__ProductID = @Default

Use this qurey for when you click NEXT
SELECT *
FROM tblProducts
WHERE Pro__ProductID =
(
SELECT MIN(Pro__ProductID)
FROM tblProducts
WHERE Pro__ProductID > @CurrentValue
)


Use this query for when yyou click PREV
SELECT *
FROM tblProducts
WHERE Pro__ProductID =
(
SELECT MAX(Pro__ProductID)
FROM tblProducts
WHERE Pro__ProductID < @CurrentValue
)
0
 
BirdbusterCommented:
Does your application require you to show all of your data at one time?
Does it use paging ? Does it have a drop down to limit rows with a default value? How long does it take to run the query in to query ananlyzer 10 seconds or shorter? If you could answer these questions and I will be able to give you a much more detailed answer.

Thanks,
Birdbuster
0
 
Paracom_IncAuthor Commented:
The form only needs to display data for one row at a time.
I'm not sure what you mean be paging maybe that's my whole problem.
Navigating from row to row is done with a couple of ComboBoxes and also using first, next, previous, and last buttons. It is the navigation via the first, next, previous, and last buttons that is the issue. Right now I'm using a BindingNavigator with a BindingSource that has a DataTable as its DataSource. The DataTable has only one column, the primary key. The DataTable is populated using a stored procedure in the SQL Server database that returns all rows in the SQL Server table sorted by an indexed column. The TableAdapter.Fill() method that populates the DataTable via the storedprocedure takes 20 seconds to execute. The stored procedure run in query analyzer takes 10 seconds to execute.

What I'm looking for is a good way to be able to move sequentially through the rows without having to spend so much time up front populating a DataTable for this purpose when the form opens. Thanks.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Gautham JanardhanCommented:
why do u want to populate the Datable on form load

cant u fetch row by row..

0
 
redpipeCommented:
Miscellaneous references to data paging:
  How To Perform Paging with the DataGrid Windows Control by Using Visual C# .NET
  http://www.123aspx.com/redir.aspx?res=27689

  101 Samples for Visual Studio 2005 => Data Access Samples => Performing Batch Updates and Data Paging
  http://msdn.microsoft.com/vstudio/downloads/101samples/default.aspx

If you like to display huge quantities of date in the grid then Virtual Mode is for you:
  Walkthrough: Implementing Virtual Mode in the Windows Forms DataGridView Control
  http://msdn2.microsoft.com/en-us/library/15a31akc.aspx
0
 
Paracom_IncAuthor Commented:
I checked out the data paging references but they weren't very helpful. The DataGrid paging article talks about how to feed pages of an already populated table into a DataGrid, but I'm trying to avoid populating the table in the first place. The sample page lists a sample named Performing Batch Updates and Data Paging, but as far as I could tell it only demonstrates batch updates. I'm not using a grid, so the grid's virtual mode is not for me.

Fetching the data row by row is what I expected to have to do, but I was looking for some suggestions regarding best ways of keeping track of where I am in the backend data table, allowing the data to be sorted on user selected columns, and using a BindingNavigator in conjunction with all of this. Thanks.
0
 
Paracom_IncAuthor Commented:
Thanks everyone for your suggestions. I've made use of many of them. It turned out that the biggest challenge was the fact that the browsing order was not based on the primary key so the simplest approaches would not work. I wrote a stored procedure that takes a prmary key as a parameter returns a range of rows in the complex sort order with the indicated row in the middle. This works very well, is very fast and is transparent to the code that cares about the DataTable.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.