help to nav through DataReader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to move through some records to get the first and last value of a
field. The od days there was movefirst, etc in ADO.
I know .ExecuteScalar() can get me the first record. But if I use a
DataReader how do I get the last record's information for a specific field in
that record?
I've looked at DataSets and can't seem to get that going either.


Any ideas?
Thanx.
 
I'm not sure if you are referring to field or record. If Field - you can
just reference it through it's index in the query or column/alias name.

If you mean last record, then you'll need to walk through the reader until
you get to the end. Readers only go one direction and they are live -

If you need to navigate- then the DataTable and DataAdapter.Fill is the way
to go - it takes a snapshot of the data and returns it - you can navigate
however you want after that.
 
ok , so if I try using a data adapter and I have the data snapshot.

How do then find a particular value of a field?
How would I then look at the record above it?
How would I then look at the first and last record?

An example might be that there are 5 fields per row, and 5 rows. The field
name is "DisplayOrder". And I'm looking for a value of 3000.

dadQuestions.Fill(" dstQuestions, "Questions")
dtblQuestions = dstQuestions.tables("Questions")

how do I navigate the datatable, many thanx!
 
How do then find a particular value of a field?

object value = dtblQuestions.Rows[0]["FieldName"];
How would I then look at the record above it?

DataRow rowAbove = dtblQuestions.Rows[x - 1];
How would I then look at the first and last record?

DataRow firstRow = dtblQuestions.Rows[0];
DataRow lastRow = dtblQuestions.Rows[dtblQuestions.Rows.Count - 1];
An example might be that there are 5 fields per row, and 5 rows. The
field name is "DisplayOrder". And I'm looking for a value of 3000.

dadQuestions.Fill(" dstQuestions, "Questions")
dtblQuestions = dstQuestions.tables("Questions")

how do I navigate the datatable, many thanx!

foreach(DataRow row in dtblQuestions.Rows) {
object order = row["DisplayOrder"];
if(order is int && (int)order == 3000)
Console.WriteLine("found one!");
}


Nathan
 
Back
Top