Solved

DataBinding to large tables

Posted on 2006-11-08
7
253 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:Paracom_Inc
7 Comments
 
LVL 3

Expert Comment

by:Birdbuster
Comment Utility
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
 

Author Comment

by:Paracom_Inc
Comment Utility
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
Comment Utility
why do u want to populate the Datable on form load

cant u fetch row by row..

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Assisted Solution

by:redpipe
redpipe earned 100 total points
Comment Utility
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
 

Author Comment

by:Paracom_Inc
Comment Utility
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
 
LVL 3

Accepted Solution

by:
Birdbuster earned 400 total points
Comment Utility
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
 

Author Comment

by:Paracom_Inc
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now