how to give data reader result as source to grid view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jagdeep gupta
    New Member
    • Aug 2010
    • 98

    how to give data reader result as source to grid view

    when i found datareader object containing data after execution of query
    simply giving gridviewdata=dr ;
    does not work
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    A DataReader retrieves a read-only, forward-only stream of data from a database.

    A GridView cannot be bound to a stream of data. It needs to be bound to a DataTable, or Collection of Objects...

    In other words, you have to convert the stream into a source that the GridView can use. You need to loop through the stream and read each row from it. Store the information into a DataTable or an Object (which you would add to an Array, or List, or collection of some sort) so that you can use it with your GridView.

    The link is to an article on the DataReader class and contains an example (in C#, VB.NET etc) on how to retrieve data from it.

    -Frinny

    Comment

    Working...