How to check the next item when using for each row

Hello, I am writing because I have a question.
I am processing the data table row by row using for each row.
Check the next row and if it is the same as the task you just processed, you need to proceed with the task. If it is not the same, you need to click Save.
(To be more specific, if No. 1 and No. 2 are the same out of a total of 4 rows, you should save after processing up to No. 2, rather than saving in the middle.)

'How can I know what the next item is in this case?

thank you.

2 Likes

Hi,

Hope the following sample helps you. (Please use index property of ForEachRow)

Regards,

1 Like

Hi

Hope you will be having a column which will denote whether the next row item is same as current row

In that case to know that next row value of a column we can use this in a IF condition

dt.Rows(dt.Rows.IndexOf(CurrentRow)+1)(“yourcolumnname”).ToString.Equals(CurrentRow(“yourcolumnname”).ToString)

Where this denotes the next row item of a column
dt.Rows(dt.Rows.IndexOf(CurrentRow)+1)(“yourcolumnname”).ToString

And this denotes the current row value that same column
CurrentRow(“yourcolumnname”).ToString

Comparing these two we can decide whether they are same or not

Hope this would help you

Cheers @dlqhqo98

1 Like

thanks!!
This is what I was looking for.
It really helped a lot!!!

Can I ask you one more thing??

I want to get the final result by tying the data table from which the result was taken as shown on the left in the image below with the same codes as shown on the right.

What should I do??

Thank you so much for your reply.
It helped a lot.

Hi,

Hope the following sample helps you.

 dtResult =dt.AsEnumerable.GroupBy(Function(r) r("Code").ToString).Select(Function(g) dtResult.LoadDataRow({g.Key}.Concat(g.Select(Function(r) r("result").ToString)).ToArray,False)).CopyToDataTable

Sample20220127-3.zip (2.7 KB)

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.