473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using DataGridView with large database tables

what is the best way to use DataGridView to view data from large
database tables? Where the sql select statement might return millions
of rows?

string connectionString = GetFinancesConnString();
string sqlSelect =
"select CheckNbr, CheckDate, CheckAmt from Disbursements" ;

SqlDataAdapter adapter =
new SqlDataAdapter(sqlSelect, connectionString);
DataTable data = new DataTable();
adapter.Fill(data);

mBindingSource1.DataSource = data;
mGrid1.DataSource = mBindingSource1;

Is the DataTable immediatately filled with all the rows returned by
the sql select stmt?

Since the grid is only displaying a page of rows at a time, do the
DataTable, SqlDataAdapter, BindingSource and DataGridView classes work
together to only return the rows actually needed to paint the control?

A 2nd question: I have an "add" button on the form which adds to the
sql table displayed in the DataGridView. I understand that to refresh
the contents of the DataGridView you have to rebind to the data
source. What about when you want the top row in the DataGridView to
be the last added row? Currently I do the following:
- prompt the form to add the row. return the keys to the added row.
- run the above code to do the sql select from database into the
DataTable and bind the DataTable to the DataGridView.
- read the DataTable sequentially to find the RowIndex of the keys
of the just added row.
- set the FirstDisplayedScrollingRowIndex property of the
DataGridView to the found DataTable row

This seems like potentially a lot of work for the system. I understand
the Sql Select stmt should be as narrowly focused as possible. What I
would like to know is if the DataGridView scales well or if I should
be looking at a custom control that displays the table contents a page
at a time.

thanks,

-Steve

Mar 11 '07 #1
2 15502
1) Check out Virtual Mode.

2) You don't have to rebind, technically speaking. If you use BindingSource
between your DGV and your data, you can just change the data source for the
BindingSource, and it will update your display immediately.

BindingSource myBindingSource = new BindingSource();
myBindingSource.DataSource = myDataSet.Tables(0);
myDataGridView.DataSource = myBindingSource;

The BindingSource also exposes a bunch of properties and methods you can
use, like Find and Filter.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"Steve Richter" <St************@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
what is the best way to use DataGridView to view data from large
database tables? Where the sql select statement might return millions
of rows?

string connectionString = GetFinancesConnString();
string sqlSelect =
"select CheckNbr, CheckDate, CheckAmt from Disbursements" ;

SqlDataAdapter adapter =
new SqlDataAdapter(sqlSelect, connectionString);
DataTable data = new DataTable();
adapter.Fill(data);

mBindingSource1.DataSource = data;
mGrid1.DataSource = mBindingSource1;

Is the DataTable immediatately filled with all the rows returned by
the sql select stmt?

Since the grid is only displaying a page of rows at a time, do the
DataTable, SqlDataAdapter, BindingSource and DataGridView classes work
together to only return the rows actually needed to paint the control?

A 2nd question: I have an "add" button on the form which adds to the
sql table displayed in the DataGridView. I understand that to refresh
the contents of the DataGridView you have to rebind to the data
source. What about when you want the top row in the DataGridView to
be the last added row? Currently I do the following:
- prompt the form to add the row. return the keys to the added row.
- run the above code to do the sql select from database into the
DataTable and bind the DataTable to the DataGridView.
- read the DataTable sequentially to find the RowIndex of the keys
of the just added row.
- set the FirstDisplayedScrollingRowIndex property of the
DataGridView to the found DataTable row

This seems like potentially a lot of work for the system. I understand
the Sql Select stmt should be as narrowly focused as possible. What I
would like to know is if the DataGridView scales well or if I should
be looking at a custom control that displays the table contents a page
at a time.

thanks,

-Steve

Mar 11 '07 #2
Hi, Steve Richter:

You have to use server cursor for accessing data tables. See the article
at http://www.udaparts.com/devguide.htm. The article tells you limitations
of ADO.NET and the reasons why you can NOT use ADO.NET for large datatable.

Wish the article helps you understanding ADO.NET.
Regards,

"Steve Richter" <St************@gmail.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
what is the best way to use DataGridView to view data from large
database tables? Where the sql select statement might return millions
of rows?

string connectionString = GetFinancesConnString();
string sqlSelect =
"select CheckNbr, CheckDate, CheckAmt from Disbursements" ;

SqlDataAdapter adapter =
new SqlDataAdapter(sqlSelect, connectionString);
DataTable data = new DataTable();
adapter.Fill(data);

mBindingSource1.DataSource = data;
mGrid1.DataSource = mBindingSource1;

Is the DataTable immediatately filled with all the rows returned by
the sql select stmt?

Since the grid is only displaying a page of rows at a time, do the
DataTable, SqlDataAdapter, BindingSource and DataGridView classes work
together to only return the rows actually needed to paint the control?

A 2nd question: I have an "add" button on the form which adds to the
sql table displayed in the DataGridView. I understand that to refresh
the contents of the DataGridView you have to rebind to the data
source. What about when you want the top row in the DataGridView to
be the last added row? Currently I do the following:
- prompt the form to add the row. return the keys to the added row.
- run the above code to do the sql select from database into the
DataTable and bind the DataTable to the DataGridView.
- read the DataTable sequentially to find the RowIndex of the keys
of the just added row.
- set the FirstDisplayedScrollingRowIndex property of the
DataGridView to the found DataTable row

This seems like potentially a lot of work for the system. I understand
the Sql Select stmt should be as narrowly focused as possible. What I
would like to know is if the DataGridView scales well or if I should
be looking at a custom control that displays the table contents a page
at a time.

thanks,

-Steve

Mar 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: thomasp | last post by:
This is a two part question, 1) The code below should display a form with a datagridview and a few command buttons. This form should allow the user to make change to the records displayed in...
3
by: Bob | last post by:
Thinking two things, 1- Creating a userControl -yeah you guessed it, a multi column drop down combobox - I've looked at several articles and did not find what I need, one that's bindable and that...
1
by: RSH | last post by:
Hi, I have a situation where I have a DDL that lists all of the tables in a particular database, and a Datagridview which appears in the same from below the DDL.. When the user selects a new...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
5
by: John Dann | last post by:
I need to display some internal program data in a grid to help with debugging (just display a simple 2D table, not edit or anything else), but I'm not an experienced database coder. AFAICS the only...
0
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I am a .NET newbie, specifically WinForms. I have a simple Winform for which I have a "How To" question: My WinForm app will display data from a FoxPro database, two tables in particular:...
1
by: weird0 | last post by:
How can i update the data in my database directly through datagridview....? Can anyone tell me the appropriate links and what is the exact event in datagridview that handles it and some explanation...
15
by: javatech007 | last post by:
I am creating a bank customer's details application. The information is stored on a Microsoft Access file and I was able to make the information appear on my VB application through text boxes and a...
1
by: Garima12 | last post by:
I am fetching data from database and displaying in DataGridView in vb.net 2.0. I am specifying- DataGridView1.DataSource = ds.Tables(0) .It fills the DataGridView with values with their colum...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.