how read the prevoius row from the sqldatareader
-
how to read the prevoius row using a sqldatareader(rs) object(opposite of rs.next())
-
how to read the prevoius row using a sqldatareader(rs) object(opposite of rs.next())
-
You can't move backwards in the data stream. Once you move forward, the previous record doesn't exist any more.
Despite everything, the person most likely to be fooling you next is yourself.
thanx. then how can i get the previous record , what is the option i can use ..
-
thanx. then how can i get the previous record , what is the option i can use ..
-
thanx. then how can i get the previous record , what is the option i can use ..
-
You need to save the current record, then when you read next the record the one you have saved is the prevous record. Obvious really!
Bob Ashfield Consultants Ltd
That's true if you only need to back up one record. Suppose you want to back up two.... The previous answer is, I think, more what the questioner needed. If you want to move forward AND backward, you need to use a DataTable, not a DataReader.
-
thanx. then how can i get the previous record , what is the option i can use ..
Instead of asking about what you think is the solution, I think that you should rather ask about what you are trying to accomplish. Why would you need the previous record? If you are trying to compare some data, perhaps that would be much faster in the database query than in the C# code?
Despite everything, the person most likely to be fooling you next is yourself.
-
Well, you can't actually use a DataSet instead of a DataReader, as you need a DataReader to populate the DataSet with data from the database. Also, if the DataReader reads from a large result, it might not be practically possible to put all the data in a DataSet. Back to prasadbuddhika about what it is that he actually is trying to do...
Despite everything, the person most likely to be fooling you next is yourself.
-
That's true if you only need to back up one record. Suppose you want to back up two.... The previous answer is, I think, more what the questioner needed. If you want to move forward AND backward, you need to use a DataTable, not a DataReader.
David Fleming wrote:
That's true if you only need to back up one record.
Which is what he asked :) The possibilities are endless - datatables, collections, arrays. It all depends on what he wants to do - and as usual there was no clue to that.
Bob Ashfield Consultants Ltd
-
Instead of asking about what you think is the solution, I think that you should rather ask about what you are trying to accomplish. Why would you need the previous record? If you are trying to compare some data, perhaps that would be much faster in the database query than in the C# code?
Despite everything, the person most likely to be fooling you next is yourself.
what i need is to read previous data to compare data with previous data.
-
what i need is to read previous data to compare data with previous data.
You can keep the data in a generic
List
which can be enumerated later for checking. Assume you are getting numbers from data reader.List<int> data = new List<int>();
using(SqlDataReader reader = getTheReader()){
if(reader.HasRows)
{
int ordinal = reader.GetOrdinal("YourColumnName");
while(reader.Read())
data.Add(reader.GetInt32());
}
reader.Close();
}// contents of reader is in list _data _ Use that to do comparison
Navaneeth How to use google | Ask smart questions
-
what i need is to read previous data to compare data with previous data.
prasadbuddhika wrote:
what i need is to read previous data to compare data with previous data.
So, you want the previous data to... eh... use it? Could you be a bit less specific, please? ;) If you for example need the previous data in order to only display one of each value, that could be done before you get the data from the database. I.e. instead of:
select Name from SomeTable order by Name
andif (Name <> PreviousName) ListBox.Items.Add(Name);
you could do:select distinct Name from SomeTable order by Name
andListBox.Items.Add(Name);
This way you would only fetch the data that you actually use from the database, instead of fetching a lot of data only to throw it away. In similar ways you can use the database to group records and calculate things like sum, average, minimum and maximum.Despite everything, the person most likely to be fooling you next is yourself.