473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to use DataReader with DataGridView in Visual Basic 2005?

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.

Aug 21 '07 #1
3 8517
On Tue, 21 Aug 2007 12:20:02 -0700, Peter
<Pe***@discussions.microsoft.comwrote:
>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.
Aug 21 '07 #2
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
"Peter" <Pe***@discussions.microsoft.comschreef in bericht
news:BB**********************************@microsof t.com...
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.
Aug 22 '07 #3
Correction
>>A webpage does not hold data
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

"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:17**********************************@microsof t.com...
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
"Peter" <Pe***@discussions.microsoft.comschreef in bericht
news:BB**********************************@microsof t.com...
>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.
Aug 22 '07 #4

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

Similar topics

5
by: .Net Sports | last post by:
I have an open datareader that gets data from an sql statement, but when I try to put it into a dataset so that my datagrid can pick it up, I get a 'System.Data.SqlClient.SqlDataReader' does not...
1
by: ME | last post by:
I was running into a problem with the DataGridView while binding it to an object Collection. I got it working and I thought others might like to know how. -------------- Problem -------------...
0
by: Crazy Cat | last post by:
Hi, I've posted on this before, but was unable to get help. I really would like to use this control, but I can't offer it to my users until I am able to resolve this problem. I am creating...
10
by: steve | last post by:
Hi All I would like to be able to change the cell borders on certain cells to none at runtime to make a group of cells appear to be merged I have tried the following in the cellformatting...
1
by: Scotty | last post by:
Hi, I am struggling with folowing problem, I am a beginner of vbnet 2005 I have a datagridview and want to use ENTER key to move instead of the TAB key. On msdn i have found the code to...
1
by: vbt | last post by:
Is it possible to load a DataGridView with a text file with the cells separated by commas? I do not have access to a program like Excel that can create a database. I am using Visual Basic...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
0
by: David Mayerovitch | last post by:
As an exercise in learning Visual Basic 2005, I am putting together a simple XML editor. I place on the form the objects DataGridView1 and DataSet1. ' Read an XML file into DataSet1:...
6
by: Bill Nguyen | last post by:
I tried almost everything ..Rows.clear() ..rowcount = 0 and the rows in a datagridview still not cleared I populated the Datagridview manually using Row.Add Any help is greatly appreciated ...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.