ADO.NET - Current Position

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

How do I find out which row I am currently on in a dataset?
I want to use a method like "movenext" in ADO 2.5 but don't think it exists,
therefore looking for an alternative.

Any help appreciated.
Dave
 
Hi Dave,

There are so many posibilities in Ado.Net
If depends what control or/and what binding you are using

If the control is a windowsform datagrid it can be (look "can be")
This sample is just to show you the increment of the row

i=datagrid1.CurrentRowIndex
mydataset.Tables(0).Rows(i).item(0) (is the first item in the dataset)

Therefore an equivalent from a recordset (the movenext and only the
movenext)
mydataset.tables(0).rows(i+1).items(0)

I hope this helps?

Cor
 
You move through records in a given table but I'm not sure what the goal is.

Let's say that you have the following:

foreach(DataRow dro in myDataSet.Tables[WhateverTable].Rows){

}
This snippet will walk the datatable for you.

At any given point, you can reference myDataSet.Tables[Whatever].Rows[x] as
well, and use x + 1 to move to the next one (being careful to make sur eyou
don't go past myDataSet.Tables[Whatever].Rows.Count

The closest thing to the move next in ADO.NET that i can think of is with a
DataReader ...it's .Read() call will move the position to the next record if
it's there. This doesn't address your problem b/c you're using a DataSet,
but remember, DataSets are disconnected objects, and you don't even need a
DataBase at all to use them.

HTH,

Bill
 
I'll be more specific...

I have a dataset that I have populated and have displayed some fields in
data-bound textboxes. I then want to be able to click a button to move to
the next record in the dataset. What I am struggling with is recognising
which record I am current on.
As an added complication (to me anyway) I am trying to do this using
ASP.NET.

Unsure whether I should be using databinding in this context.
 
Hi Dave,

Dave said:
I'll be more specific...

I have a dataset that I have populated and have displayed some fields in
data-bound textboxes. I then want to be able to click a button to move to
the next record in the dataset. What I am struggling with is recognising
which record I am current on.
As an added complication (to me anyway) I am trying to do this using
ASP.NET.

I see. You might add the primary key field somewhere hidden, or store the
current position in a session variable perhaps.
You see, asp.net databinding is unidirectional - it just puts data there and
after that "who cares" :)
 
This works for me

Me.BindingContext(DataSetName, "TableName").Position += 1 (moves 1 record
positive)

Me.BindingContext(DataSetName, "TableName").Position -= 1 (moves 1 record
negative)

Frank
 
Back
Top