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:ID | Name | FriendlyName | MetaClassType |
---|
1 | NewsItems | News | Article |
2 | ClientPage | Client Page | Page |
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!