DataTable - is there a way to traverse (.next, .previous, .first, .last etc..)

Is there a way to to traverse DataTable like VB/.NET (.next, .previous, .first, .last etc…) ? I have requirement to skip certain rows. I donot want to use the option dataTable.rows(index) option.

@skini76
You can use
dt.Select().Skip(m).Take(n)
m-number of rows you want to skip
n-number of rows you want to take

Regards,
Mahesh

There is no method such as “AsEnumerable” …

@skini76
try this
You can use
dt.Select().Skip(m).Take(n)
m-number of rows you want to skip
n-number of rows you want to take

Regards,
Mahesh

1 Like

What will be the return value ? Subset of the dataTable ?

@skini76
Yes

Ok, but this may not work for me, because I need to traverse in the original dataTable itself.

@skini76
May I know your requirement

Regards,
Mahesh

for each row in dataTable.EOF
{

//skip a row based on a key
if (row.item(“action”).toString = “skip”)
{
skip one row
}

var1 = row.item(“field1”).toString;
var2 = row.item(“field2”).toString;

// some actions
}

@skini76
I think you can get the rows directly whose column value is not equal to skip and then run foreach row to perform the operations.

Regards,
Mahesh

How to skip ? In VB / .Net we have options like .Next

@skini76
sorry if iam wrong.
You need not to perform anything if the action column contains skip right
then place entire thing in if condition.

Regards,
Mahesh

If am not wrong.
You can filter all the rows containing Value “Skip” and then process.
Syntax:-
(from line in Datatable.select where(line.ColumnName<>“Skip”) select line).ToArray()

Sorry, even this may not work for me. All the records (rows) should present in the dataTable when traversing, because the 2-3 consecutive rows are related to single action some action is performed each row before I move to the next row ie the data is scattered across 2-3 rows for one single action.
If there is no other option, then I will try this. At present I am using while loop inplace of for each row.

RowNo = 1
While (RowNo<dt_fixedincome.Rows.Count)