PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Filling a data grid with a Datareader

Reply

Filling a data grid with a Datareader

 
Thread Tools Rate Thread
Old 06-02-2006, 03:15 AM   #1
=?Utf-8?B?QW50?=
Guest
 
Posts: n/a
Default Filling a data grid with a Datareader


Hi, I'm using a SP with one input parameter to return query results to a
Datareader. I then want to add the rows in the data reader into a data grid.

Can you 'bind' a datareader to a data grid? If not, how would do it?

The data grid will be read only.

What is the best approach for this? Datareader? Data set? If so, how would I
return the resultant rows from the SP into a data set. I'm quite new to
ADO.NET

Many thanks in advance for any ideas
Ant
  Reply With Quote
Old 06-02-2006, 06:18 AM   #2
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: Filling a data grid with a Datareader

Ant,

This newsgroup is full of people who tell that they use a stored procedure.
For AdoNet that is not so interesting (you have to use parameters, however
that you should forever).

More interesting for this question is if you use a windowforms datagrid or a
webform datagrid.

To the last you can bind the datareader to that datagrid using its
datasource and after that databind that. For the first you cannot.

I hope this helps,

Cor


  Reply With Quote
Old 06-02-2006, 07:17 AM   #3
=?Utf-8?B?QW50?=
Guest
 
Posts: n/a
Default Re: Filling a data grid with a Datareader

Hi Cor,

I'm using a Web form datagrid so i guess I can't bind it. So then, how would
I load the Datareader data into the datagrid? What methods does the Datagrid
expose to allow me to do this?

Thanks

"Cor Ligthert [MVP]" wrote:

> Ant,
>
> This newsgroup is full of people who tell that they use a stored procedure.
> For AdoNet that is not so interesting (you have to use parameters, however
> that you should forever).
>
> More interesting for this question is if you use a windowforms datagrid or a
> webform datagrid.
>
> To the last you can bind the datareader to that datagrid using its
> datasource and after that databind that. For the first you cannot.
>
> I hope this helps,
>
> Cor
>
>
>

  Reply With Quote
Old 06-02-2006, 07:44 AM   #4
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: Filling a data grid with a Datareader

Ant,

Yes you can use to a datareader (as I tried to tell in my previous answer).

See the first sample in this article

http://msdn.microsoft.com/library/d...blesortable.asp

I hope this helps,

Cor

> Hi Cor,
>
> I'm using a Web form datagrid so i guess I can't bind it. So then, how
> would
> I load the Datareader data into the datagrid? What methods does the
> Datagrid
> expose to allow me to do this?
>
> Thanks
>
> "Cor Ligthert [MVP]" wrote:
>
>> Ant,
>>
>> This newsgroup is full of people who tell that they use a stored
>> procedure.
>> For AdoNet that is not so interesting (you have to use parameters,
>> however
>> that you should forever).
>>
>> More interesting for this question is if you use a windowforms datagrid
>> or a
>> webform datagrid.
>>
>> To the last you can bind the datareader to that datagrid using its
>> datasource and after that databind that. For the first you cannot.
>>
>> I hope this helps,
>>
>> Cor
>>
>>
>>



  Reply With Quote
Old 06-02-2006, 09:28 AM   #5
=?Utf-8?B?QW50?=
Guest
 
Posts: n/a
Default Re: Filling a data grid with a Datareader

Thanks very much for your help Cor,
Ant

"Cor Ligthert [MVP]" wrote:

> Ant,
>
> Yes you can use to a datareader (as I tried to tell in my previous answer).
>
> See the first sample in this article
>
> http://msdn.microsoft.com/library/d...blesortable.asp
>
> I hope this helps,
>
> Cor
>
> > Hi Cor,
> >
> > I'm using a Web form datagrid so i guess I can't bind it. So then, how
> > would
> > I load the Datareader data into the datagrid? What methods does the
> > Datagrid
> > expose to allow me to do this?
> >
> > Thanks
> >
> > "Cor Ligthert [MVP]" wrote:
> >
> >> Ant,
> >>
> >> This newsgroup is full of people who tell that they use a stored
> >> procedure.
> >> For AdoNet that is not so interesting (you have to use parameters,
> >> however
> >> that you should forever).
> >>
> >> More interesting for this question is if you use a windowforms datagrid
> >> or a
> >> webform datagrid.
> >>
> >> To the last you can bind the datareader to that datagrid using its
> >> datasource and after that databind that. For the first you cannot.
> >>
> >> I hope this helps,
> >>
> >> Cor
> >>
> >>
> >>

>
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off