How to use DataReader with DataGridView in Visual Basic 2005?

G

Guest

I'm trying to add a datagridview control to a Windows Form to display
read-only information in visual basic 2005. My understanding is that
datareader will be faster for this purpose. I have the following questions:

1. Can DataReader be bound DIRECTLY to DataGridView?

2. If DataReader cannot be bound directly to DataGridView, how can I load a
DataReader into a DataTable and bind the DataTable to DataGridView? Can the
DataTable be a standalone one without DataSet?

3. Is there other standard control that I should use instead of
DataGridView? I see there is something called ListView.
 
J

Jack Jackson

I'm trying to add a datagridview control to a Windows Form to display
read-only information in visual basic 2005. My understanding is that
datareader will be faster for this purpose.

Faster than what? A DataReader is the basic object that reads data
from a database. You can use the DataReader by itself, or in
conjunction with a DataAdapter, DataTable and DataSet.
I have the following questions:

1. Can DataReader be bound DIRECTLY to DataGridView?

No. To use only a DataReader, you can use an unbound DataGridView.
Read through the records in the DataReader and add each to the
DataGridView.
2. If DataReader cannot be bound directly to DataGridView, how can I load a
DataReader into a DataTable and bind the DataTable to DataGridView?

Look at DataTable.Load(). Set DataGridView.DataSource to the
DataTable.
Can the DataTable be a standalone one without DataSet?
Yes.

3. Is there other standard control that I should use instead of
DataGridView? I see there is something called ListView.

If you are displaying multiple columns you almost certainly want a
DataGridView.
 
C

Cor Ligthert[MVP]

Peter,

Every control in windowsforms is only showing data that is in memory.

A datareader reads one row of data every time, to show that data with a
datagridview is a little bit out of sense.

Don't compare a windowsform with a webpage. A webpage does not hold data,
the page holds itself data, although that is always based on the behaviour
of the browsers and inside the browser data.

You can use a datareader, but only if you first set the data from your
resultset in a collection The collectionBase is a very easy one for that to
use (not the one from the microsoft visualbasic namespace). However a
datatable is nothing more than a very advanced collection class. Adonet uses
the datareader internal in the dataadapter.fill, however has build in all
kind of extra possibilities.

The advantage of using a datareader? That is easier to use when you build by
hand your own strongly typed collection classes where the data comes from
many joined tables. I do that , but for sure not for situations were an
update from the data is needed.

Cor
 
C

Cor Ligthert[MVP]

Correction
A webpage does not use seperated data from the computers memory
................................
(it is difficult to explain what i mean in a message, I should need a
drawing board for that).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top