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


#1

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.


#2

@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


#3

There is no method such as “AsEnumerable” …


#4

@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


#5

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


#6

@skini76
Yes


#7

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


#8

@skini76
May I know your requirement

Regards,
Mahesh


#9

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
}


#10

@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


#11

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


#12

@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


#13

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()


#14

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)