Is there a Winforms grid to which I can readily bind a datareader
(purely for read-only visualisation of the datareader data and using
the 1.1 framework)? Or is this in some way not regarded as a
legitimate use for the datareader?

JGD

Re: Binding a datareader to a grid by William

William
Sat Jul 24 12:04:18 CDT 2004

No, you can't bind a DataReader to a DataGrid in a WinForms application.
You'll need to use Fill. Some might suggest writing code to create a
DataTable from a DataReader, but I have not seen anyone write code as
efficient as Fill.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"John Dann" <news@prodata.co.uk> wrote in message
news:dc35g0d55q1sb8q09nhn7rtq4g8kkvguqf@4ax.com...
> Is there a Winforms grid to which I can readily bind a datareader
> (purely for read-only visualisation of the datareader data and using
> the 1.1 framework)? Or is this in some way not regarded as a
> legitimate use for the datareader?
>
> JGD



Re: Binding a datareader to a grid by Earl

Earl
Sat Jul 24 12:07:03 CDT 2004

You could use the datareader to return the data you need to populate a
datatable and bind that to a read-only datagrid.

"John Dann" <news@prodata.co.uk> wrote in message
news:dc35g0d55q1sb8q09nhn7rtq4g8kkvguqf@4ax.com...
> Is there a Winforms grid to which I can readily bind a datareader
> (purely for read-only visualisation of the datareader data and using
> the 1.1 framework)? Or is this in some way not regarded as a
> legitimate use for the datareader?
>
> JGD



Re: Binding a datareader to a grid by John

John
Sat Jul 24 12:22:05 CDT 2004

On Sat, 24 Jul 2004 10:04:18 -0700, "William \(Bill\) Vaughn"
<billvaRemoveThis@nwlink.com> wrote:

>No, you can't bind a DataReader to a DataGrid in a WinForms application.

Thanks for the response. Really I was wondering whether there was any
alternative to a DataGrid, eg perhap a 3rd party grid control, that
would allow direct binding.

JGD

Re: Binding a datareader to a grid by Scott

Scott
Sat Jul 24 15:16:12 CDT 2004

You can't bind a DataReader to any grid because a grid shows many records
and a DataReader is only populated with one row of data at any given time.


"John Dann" <news@prodata.co.uk> wrote in message
news:dc35g0d55q1sb8q09nhn7rtq4g8kkvguqf@4ax.com...
> Is there a Winforms grid to which I can readily bind a datareader
> (purely for read-only visualisation of the datareader data and using
> the 1.1 framework)? Or is this in some way not regarded as a
> legitimate use for the datareader?
>
> JGD



Re: Binding a datareader to a grid by Miha

Miha
Sat Jul 24 15:25:03 CDT 2004

Hi John,

Why would you want to?
I mean, the data retrieved should be stored somewhere.
So, why store data into the grid (as you want)?
Isn't storing the data in universal container such as dataset a better
approach (rhetorical question ;-))?
In this way, grid (each grid) doesn't need to provide its own data container
and data is stored in a way that other controls can use it.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"John Dann" <news@prodata.co.uk> wrote in message
news:li65g05hoaeqccen6fniprdj51bl877br7@4ax.com...
> On Sat, 24 Jul 2004 10:04:18 -0700, "William \(Bill\) Vaughn"
> <billvaRemoveThis@nwlink.com> wrote:
>
> >No, you can't bind a DataReader to a DataGrid in a WinForms application.
>
> Thanks for the response. Really I was wondering whether there was any
> alternative to a DataGrid, eg perhap a 3rd party grid control, that
> would allow direct binding.
>
> JGD



Re: Binding a datareader to a grid by John

John
Sat Jul 24 15:47:44 CDT 2004

On Sat, 24 Jul 2004 22:25:03 +0200, "Miha Markic [MVP C#]" <miha at
rthand com> wrote:

>Why would you want to?
>I mean, the data retrieved should be stored somewhere.
>So, why store data into the grid (as you want)?
>Isn't storing the data in universal container such as dataset a better
>approach (rhetorical question ;-))?
>In this way, grid (each grid) doesn't need to provide its own data container
>and data is stored in a way that other controls can use it.

Well, I can well believe that you're right and quite possibly I'm not
approaching this in the best way conceptually.

But the project calls for a subset of data from a large database to be
bound to a chart. Especially in development but also to some extent in
subsequent use I can imagine that it will be quite useful to
crosscheck unexpected chart results against the underlying data.
(Especially when, as real-time instrumental data, it won't be feasible
to rigorously validate all data that's added to the database.) The
chart might need to be refreshed every minute or more frequently and a
datareader seems to be the fastest way to make a selection from a
database that might run to a million rows or more. But creating a
dataset from the datareader and then binding that to a Datagrid in
order to visualise the data in numeric terms seems an unnecessary and
potentially slow step. Hence why I was looking for a way of binding
the datareader directly to a read-only grid.

JGD

Re: Binding a datareader to a grid by William

William
Sat Jul 24 16:02:08 CDT 2004

Hi Scott:

I see the others have answered your question but I'd like to mention the new
stuff in ADO.NET 2.0 that addresses this issue. Also, you could create a
Subclassed grid, simple inherit from DataGird and you can come up with your
own method to load the grid from a Reader if you really need this
functionality. You're going to have to bind it to a
datatable/dataset/dataview or some other IList object (Actually my memory is
foggy now but I think you can bind to anything that implements IList) or
strongly typed collection. So you can build a datatable from the reader or
build a collection from it and bind to either of those but it'll take some
work. Since Readers work best for read only scenarios and grids are usually
used for editing in the winforms context -probably not a big need for this
whereas on the web there is b/c it's usually a read only scenario (and
although you can 'edit' in a web grid, the underlying story is a bit
different which makes the reader a nice choice)

In ASP.NET you are allowed to bind to a reader, actually
dataGrid.DataSource = myCommand.ExecuteReader(); It handles the
while(reader.Read()) for you and builds a datatable. It's a clunky
implementation though b/c the reader may not have any rows so you have to
put in an extra check to verify the grid will have something in it.

In ADO.NET 2.0 you can do something similar with the DataTable's .Load
method. You can load a DataTable from a DataReader WITHOUT reading through
it. So assuming I just called ExecuteReader on a reader named dr I could to
this:

DataTable dt = new DataTable("TableFromReader");
dt.Lead(dr); //Didn't have to do anything other than call ExecuteReader
before this somewhere
DataGrid1.DataSource = dt; //Will work in Winforms!

You can also do the reverse, get a Reader from a DataTable!!!!!

The DataTable has a GetReader method , which will give you a DataReader
from a DataTable
I have some examples of all of this here
http://www.knowdotnet.com/articles/miscadonet.html
or here
http://msmvps.com/williamryan/archive/2004/07/14/10090.aspx

--

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
http://www.devbuzz.com | http://www.knowdotnet.com
https://www.windowsembeddedeval.com/community/newsgroups
"John Dann" <news@prodata.co.uk> wrote in message
news:dc35g0d55q1sb8q09nhn7rtq4g8kkvguqf@4ax.com...
> Is there a Winforms grid to which I can readily bind a datareader
> (purely for read-only visualisation of the datareader data and using
> the 1.1 framework)? Or is this in some way not regarded as a
> legitimate use for the datareader?
>
> JGD



Re: Binding a datareader to a grid by Scott

Scott
Sat Jul 24 19:07:27 CDT 2004

Actually, I didn't ask a question, John did.


"William Ryan eMVP" <dotnetguru@comcast.nospam.net> wrote in message
news:%23jnRBDccEHA.2812@TK2MSFTNGP11.phx.gbl...
> Hi Scott:
>
> I see the others have answered your question but I'd like to mention the
new
> stuff in ADO.NET 2.0 that addresses this issue. Also, you could create a
> Subclassed grid, simple inherit from DataGird and you can come up with
your
> own method to load the grid from a Reader if you really need this
> functionality. You're going to have to bind it to a
> datatable/dataset/dataview or some other IList object (Actually my memory
is
> foggy now but I think you can bind to anything that implements IList) or
> strongly typed collection. So you can build a datatable from the reader or
> build a collection from it and bind to either of those but it'll take some
> work. Since Readers work best for read only scenarios and grids are
usually
> used for editing in the winforms context -probably not a big need for this
> whereas on the web there is b/c it's usually a read only scenario (and
> although you can 'edit' in a web grid, the underlying story is a bit
> different which makes the reader a nice choice)
>
> In ASP.NET you are allowed to bind to a reader, actually
> dataGrid.DataSource = myCommand.ExecuteReader(); It handles the
> while(reader.Read()) for you and builds a datatable. It's a clunky
> implementation though b/c the reader may not have any rows so you have to
> put in an extra check to verify the grid will have something in it.
>
> In ADO.NET 2.0 you can do something similar with the DataTable's .Load
> method. You can load a DataTable from a DataReader WITHOUT reading
through
> it. So assuming I just called ExecuteReader on a reader named dr I could
to
> this:
>
> DataTable dt = new DataTable("TableFromReader");
> dt.Lead(dr); //Didn't have to do anything other than call ExecuteReader
> before this somewhere
> DataGrid1.DataSource = dt; //Will work in Winforms!
>
> You can also do the reverse, get a Reader from a DataTable!!!!!
>
> The DataTable has a GetReader method , which will give you a DataReader
> from a DataTable
> I have some examples of all of this here
> http://www.knowdotnet.com/articles/miscadonet.html
> or here
> http://msmvps.com/williamryan/archive/2004/07/14/10090.aspx
>
> --
>
> --
>
> W.G. Ryan, eMVP
>
> Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
> Let Microsoft know!
> http://www.devbuzz.com | http://www.knowdotnet.com
> https://www.windowsembeddedeval.com/community/newsgroups
> "John Dann" <news@prodata.co.uk> wrote in message
> news:dc35g0d55q1sb8q09nhn7rtq4g8kkvguqf@4ax.com...
> > Is there a Winforms grid to which I can readily bind a datareader
> > (purely for read-only visualisation of the datareader data and using
> > the 1.1 framework)? Or is this in some way not regarded as a
> > legitimate use for the datareader?
> >
> > JGD
>
>



Re: Binding a datareader to a grid by William

William
Sat Jul 24 19:42:21 CDT 2004

If you're considering creating a chart, I would suggest that you take a look
at SQL Server 2000 Reporting Services. It's designed specifically for your
needs.
If you want to stick with a DataGrid, consider that the Fill method uses the
DataReader to populate the DataTable. If the query is efficient, you won't
see any performance hit over writing your own code.
Yes, there might be another third-party control, but I'm not familiar with
one.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"John Dann" <news@prodata.co.uk> wrote in message
news:li65g05hoaeqccen6fniprdj51bl877br7@4ax.com...
> On Sat, 24 Jul 2004 10:04:18 -0700, "William \(Bill\) Vaughn"
> <billvaRemoveThis@nwlink.com> wrote:
>
> >No, you can't bind a DataReader to a DataGrid in a WinForms application.
>
> Thanks for the response. Really I was wondering whether there was any
> alternative to a DataGrid, eg perhap a 3rd party grid control, that
> would allow direct binding.
>
> JGD



Re: Binding a datareader to a grid by Samuel

Samuel
Sat Jul 24 19:50:39 CDT 2004

John,

You might want to take a look at the Infragistics UltraWinChart controls.
They will directly bind to a datatable and create nice looking charts of
many styles for both Windows Forms and ASP.NET.

http://infragistics.com/products/charting.asp?sec=1

-Sam Matzen


"John Dann" <news@prodata.co.uk> wrote in message
news:li65g05hoaeqccen6fniprdj51bl877br7@4ax.com...
> On Sat, 24 Jul 2004 10:04:18 -0700, "William \(Bill\) Vaughn"
> <billvaRemoveThis@nwlink.com> wrote:
>
> >No, you can't bind a DataReader to a DataGrid in a WinForms application.
>
> Thanks for the response. Really I was wondering whether there was any
> alternative to a DataGrid, eg perhap a 3rd party grid control, that
> would allow direct binding.
>
> JGD



Re: Binding a datareader to a grid by William

William
Sat Jul 24 21:28:09 CDT 2004

Ok, sorry about that. My reader had it listed first but that explains the
RE:

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
"Scott M." <s-mar@nospam.nospam> wrote in message
news:enVs5sdcEHA.2840@TK2MSFTNGP11.phx.gbl...
> Actually, I didn't ask a question, John did.
>
>
> "William Ryan eMVP" <dotnetguru@comcast.nospam.net> wrote in message
> news:%23jnRBDccEHA.2812@TK2MSFTNGP11.phx.gbl...
> > Hi Scott:
> >
> > I see the others have answered your question but I'd like to mention the
> new
> > stuff in ADO.NET 2.0 that addresses this issue. Also, you could create
a
> > Subclassed grid, simple inherit from DataGird and you can come up with
> your
> > own method to load the grid from a Reader if you really need this
> > functionality. You're going to have to bind it to a
> > datatable/dataset/dataview or some other IList object (Actually my
memory
> is
> > foggy now but I think you can bind to anything that implements IList) or
> > strongly typed collection. So you can build a datatable from the reader
or
> > build a collection from it and bind to either of those but it'll take
some
> > work. Since Readers work best for read only scenarios and grids are
> usually
> > used for editing in the winforms context -probably not a big need for
this
> > whereas on the web there is b/c it's usually a read only scenario (and
> > although you can 'edit' in a web grid, the underlying story is a bit
> > different which makes the reader a nice choice)
> >
> > In ASP.NET you are allowed to bind to a reader, actually
> > dataGrid.DataSource = myCommand.ExecuteReader(); It handles the
> > while(reader.Read()) for you and builds a datatable. It's a clunky
> > implementation though b/c the reader may not have any rows so you have
to
> > put in an extra check to verify the grid will have something in it.
> >
> > In ADO.NET 2.0 you can do something similar with the DataTable's .Load
> > method. You can load a DataTable from a DataReader WITHOUT reading
> through
> > it. So assuming I just called ExecuteReader on a reader named dr I
could
> to
> > this:
> >
> > DataTable dt = new DataTable("TableFromReader");
> > dt.Lead(dr); //Didn't have to do anything other than call ExecuteReader
> > before this somewhere
> > DataGrid1.DataSource = dt; //Will work in Winforms!
> >
> > You can also do the reverse, get a Reader from a DataTable!!!!!
> >
> > The DataTable has a GetReader method , which will give you a DataReader
> > from a DataTable
> > I have some examples of all of this here
> > http://www.knowdotnet.com/articles/miscadonet.html
> > or here
> > http://msmvps.com/williamryan/archive/2004/07/14/10090.aspx
> >
> > --
> >
> > --
> >
> > W.G. Ryan, eMVP
> >
> > Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
> > Let Microsoft know!
> > http://www.devbuzz.com | http://www.knowdotnet.com
> > https://www.windowsembeddedeval.com/community/newsgroups
> > "John Dann" <news@prodata.co.uk> wrote in message
> > news:dc35g0d55q1sb8q09nhn7rtq4g8kkvguqf@4ax.com...
> > > Is there a Winforms grid to which I can readily bind a datareader
> > > (purely for read-only visualisation of the datareader data and using
> > > the 1.1 framework)? Or is this in some way not regarded as a
> > > legitimate use for the datareader?
> > >
> > > JGD
> >
> >
>
>



Re: Binding a datareader to a grid by Miha

Miha
Sun Jul 25 01:42:31 CDT 2004


"John Dann" <news@prodata.co.uk> wrote in message
news:kbi5g0t7dikumv2n8d0ag6i9rgannkr928@4ax.com...
> On Sat, 24 Jul 2004 22:25:03 +0200, "Miha Markic [MVP C#]" <miha at
> rthand com> wrote:
>
> >Why would you want to?
> >I mean, the data retrieved should be stored somewhere.
> >So, why store data into the grid (as you want)?
> >Isn't storing the data in universal container such as dataset a better
> >approach (rhetorical question ;-))?
> >In this way, grid (each grid) doesn't need to provide its own data
container
> >and data is stored in a way that other controls can use it.
>
> Well, I can well believe that you're right and quite possibly I'm not
> approaching this in the best way conceptually.
>
> But the project calls for a subset of data from a large database to be
> bound to a chart. Especially in development but also to some extent in
> subsequent use I can imagine that it will be quite useful to
> crosscheck unexpected chart results against the underlying data.
> (Especially when, as real-time instrumental data, it won't be feasible
> to rigorously validate all data that's added to the database.) The
> chart might need to be refreshed every minute or more frequently and a
> datareader seems to be the fastest way to make a selection from a
> database that might run to a million rows or more. But creating a
> dataset from the datareader and then binding that to a Datagrid in
> order to visualise the data in numeric terms seems an unnecessary and
> potentially slow step. Hence why I was looking for a way of binding
> the datareader directly to a read-only grid.

But still, you have to fetch and store data somewhere. That's exactly what
dataadapter does - it uses datareader to store data in dataset.
If you want to retrieve or update just a part of data - no problem,
dataadapter does it for you (based on sql select statement) assuming you
have a primary key defined (you have to have it if you want data updating).
I reallly don't see any overhead here.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com