Hi,
Why datareader is forward only?
Thanks, in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Oct 3, 2011, 4:33 PM
If the only requirement is to be able to access the previous record, then the code to retain the previous record is trivial.
Manikavelu VelayuthamPosted Oct 3, 2011, 7:22 AM
VulpesPosted Oct 3, 2011, 6:43 AM
Prabhu RajaPosted Oct 3, 2011, 5:55 AM
Why DataReader is Forward Only, the Answer is simple, To increase Performance Because i already described that DataReader is Light-weight Component. The Execution time is slow then work with Datasets. If we need Both Back and Forword Options, We may try with DataTables.
Dataset is an heavy-weight Component, But we Can use Dataset as DataSource But not DataReader as DataSource.
Manikavelu VelayuthamPosted Oct 3, 2011, 5:03 AM
Some said like it will fetch only one record at a time, thats why its forward only like that.
My question here is if the DataReader is capable of fetching only one record at a time, why cant it be developed to fetch the previous row also and why its developed to fetch only the next row and not the previous row ?
Any appropriate reason why it is developed in a way that it cant fetch the previous row ?
Prabhu RajaPosted Oct 3, 2011, 3:27 AM
For Example: In Array's, the Index Option Allows to get next and previous data. Like that why we Can't do the same by using DataReader?
Manikavelu VelayuthamPosted Oct 3, 2011, 3:20 AM
Prabhu RajaPosted Oct 3, 2011, 2:06 AM
DataReaader is connected object and one can process the rows that are returned by query, one at a time. It discards every row after you have gone through it and so it is extremely fast.It contains only read-only data, so no updates are allowed using DataReaderobjects.
Thank You
Hemant KumarPosted Oct 3, 2011, 12:55 AM
A DataReader is a stream of data that is returned from a database query. When the query is executed, the first row is returned to the DataReader via the stream. The stream then remains connected to the database, poised to retrieve the next record. The DataReader reads one row at a time from the database and can only move forward, one record at a time. As the DataReader reads the rows from the database, the values of the columns in each row can be read and evaluated, but they cannot be edited.
Generally we use datareader ado.net control where we don't need go to previous row like binding a dropdown or data repeater control. To keep it light weighted microsoft support forward only functionality in datareader control.
Pravin MorePosted Oct 3, 2011, 12:28 AM
because DataSet works as connected architecture . The DataReader reads one row at a time
from the database and can only move forward, one record at a time. when it reads next row it descards pervious row,thats the reason it cant go backward.In prohramming language it work as 1way linked list.
Thank You,
Pravin.