By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

binding datareader to datagrid in C# windows form

P: n/a
Hi,

Is it possible to bind DataReader to a DataGrid in C# windows form? And
how?
And can we update data in a DataSet by using the DataReader?
Thanks for help.
Jason
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> Is it possible to bind DataReader to a DataGrid in C# windows form?

No you can't directly. Read the data into a DataSet, and bind the grid to
it.
And can we update data in a DataSet by using the DataReader?


No, DataReaders represent a READ ONLY, FORWARD ONLY cursor. Use a
DataAdapter in order to update the data.

Regards - Octavio
Nov 17 '05 #2

P: n/a
Then why do we need a DataReader? Sounds that DataSet can do anything.

"Octavio Hernandez" <do****@danysoft.com> glsD:eN**************@TK2MSFTNGP09.phx.g bl...
Is it possible to bind DataReader to a DataGrid in C# windows form?


No you can't directly. Read the data into a DataSet, and bind the grid to
it.
And can we update data in a DataSet by using the DataReader?


No, DataReaders represent a READ ONLY, FORWARD ONLY cursor. Use a
DataAdapter in order to update the data.

Regards - Octavio

Nov 17 '05 #3

P: n/a
Hi Jason,
I don't think it'll be possible.
1) DataReader does not implement any specific interface so that it can
be bindable
2) DataReader is for reading data.So if some how u r able to bind
that,it won't allow u to edit that.So it's of no use.
3) DataReader is forward only,that means u can get a record at a time
but can't traverse back to the prev record.
I think the last (most important one!!)reason would be ---
ADO.NET follows Disconnected Model.But DataReader operates in
connected mode.So there is no scope to retrieve data from data source
and then modify it and save it,in case of DataReader.

If u have such a requirement then use DataSet/Disconeccted model
instead of datareader. :)

From
Arindam
Jason Huang wrote:
Hi,

Is it possible to bind DataReader to a DataGrid in C# windows form? And
how?
And can we update data in a DataSet by using the DataReader?
Thanks for help.
Jason


Nov 17 '05 #4

P: n/a
The DataReader allows us to read rows from a result set and store them in a
DataTable (DataSet).
For instance, the DataAdapter internally uses a DataReader in order to
execute the SELECT statement.

Regards - Octavio

"Jason Huang" <Ja************@hotmail.com> escribi en el mensaje
news:Ot**************@tk2msftngp13.phx.gbl...
Then why do we need a DataReader? Sounds that DataSet can do anything.

"Octavio Hernandez" <do****@danysoft.com>
glsD:eN**************@TK2MSFTNGP09.phx.g bl...
Is it possible to bind DataReader to a DataGrid in C# windows form?


No you can't directly. Read the data into a DataSet, and bind the grid to
it.
And can we update data in a DataSet by using the DataReader?


No, DataReaders represent a READ ONLY, FORWARD ONLY cursor. Use a
DataAdapter in order to update the data.

Regards - Octavio


Nov 17 '05 #5

P: n/a
On Fri, 19 Aug 2005 16:54:30 +0800, "Jason Huang"
<Ja************@hotmail.com> wrote:
Then why do we need a DataReader? Sounds that DataSet can do anything.

Jason,

A DataSet cannot do anything on its own. It merely represent a
disconnected chunk of data with any data updates and, optionally,
validation errors, nothing else. You can use it in a variety of ways,
including data binding.

In general, you'd use a DataReader or DataAdapter to populate a
DataSet, make changes to the data in the DataSet either directly or
thru data binding and then use a DataAdapter to submit your changes to
the database.

The above briefly describes the disconnected nature of ADO.NET: you
can acquire any data in a form of a DataSet, pass it around as much as
you like, within a single application or between many apps, make
changes to it (inserts/updates/deletes), and then hand it back to a
DataAdapter to submit the changes to the underlyng data storage.

"Octavio Hernandez" <do****@danysoft.com> glsD:eN**************@TK2MSFTNGP09.phx.g bl...
Is it possible to bind DataReader to a DataGrid in C# windows form?


No you can't directly. Read the data into a DataSet, and bind the grid to
it.
And can we update data in a DataSet by using the DataReader?


No, DataReaders represent a READ ONLY, FORWARD ONLY cursor. Use a
DataAdapter in order to update the data.

Regards - Octavio

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.