Timothy

Timothy

  • NA
  • 2
  • 0

If a DataReader holds one record at a time, then why...

Aug 4 2009 12:02 AM
My understanding is that a DataReader can only hold one record in memory at any given time and has to keep the connection to the database open to read subsequent records in a forward only manner.  

How is it then that I can bind a dataReader to a DataGrid and display multiple rows?
  I just don't get it.   I currently have this code:

            DbDataReader ddr = GetMetaClasses();
            GridView1.DataSource = ddr;
            GridView1.DataBind();

GetMetaClasses executes this stored procedure:

SELECT * FROM MetaClasses;  

This is what my page displays:

IDNameFriendlyNameMetaClassType
1NewsItemsNews Article
2ClientPageClient PagePage

I don't understand how binding to the dataReader would work successfully and show all the results from the query if a dataReader can only hold one record in memory.   Can someone please explain??  Thanks in advance!

Answers (2)