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.

Re: help to nav through DataReader by W

W
Thu Jan 27 18:12:46 CST 2005

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.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Chris" <Chris@discussions.microsoft.com> wrote in message
news:D96FC496-EF61-4447-BFAF-B562C1091551@microsoft.com...
> 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.



Re: help to nav through DataReader by Chris

Chris
Thu Jan 27 18:37:05 CST 2005

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!

> 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.
>
> --
> W.G. Ryan MVP (Windows Embedded)
>
> TiBA Solutions
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Chris" <Chris@discussions.microsoft.com> wrote in message
> news:D96FC496-EF61-4447-BFAF-B562C1091551@microsoft.com...
> > 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.
>
>
>

Re: help to nav through DataReader by Nathan

Nathan
Thu Jan 27 21:45:44 CST 2005

> 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