For each row of a data table

Hi all,

How can I do a for each row activity that only works for a row that contains specific word/character?

Thanks!

1 Like

HI @jasperlzx,

Use for each row activity
use if Condition
String.join(",",row.ItemArray).Contains("yourvalue")

if true do your operations else leave it go to next record.

Regards,
Arivu

2 Likes

Hello,

Can you be a bit more specific? The word/character can be in any column or a specific column?

If itā€™s a specific column, you can put an If activity inside the For Each Row activity and put the following condition:

row.Item("ColumnName").ToString.Contains("word")

If itā€™s any column, inside the For Each Row you can put a For Each activity and iterate through datatable.Columns and inside this loop put the If activity with the following condition:

row.Item(column.ColumnName).ToString.Contains("word")

, where ā€˜columnā€™ is the current iteration of the datatable.Columns loop.

If you want to extract all rows that meet this condition and only iterate through these for further processing, you can use LINQ to obtain the rows:

datatable.AsEnumerable().Where(Function(x) x.Item("ColumnName").ToString.Contains("word")).ToArray

3 Likes

hi, this does not work.

hi, its usually in column A. its every 6/7 row after one other but I do not have column header

You can also give it the column index if you donā€™t know the column name. If itā€™s the first column then the index is 0:

row.Item(0).ToString.Contains(ā€œwordā€)

@jasperlzx If you are aware of which column you need to look into, you can filter your data table and get only rows that have required value and then loop through only those rows for further processing.

filteredRows = yourDataTable.Select(ā€œ[Column_Name] like '%ā€ + Character/WordToCheck + ā€œ%'ā€)

user for each to loop through filtered rows

1 Like

can U show an example? I donā€™t have a column name as the column also contains data that are not related.

Hereā€™s an example: ExcelWIthoutHeader.zip (8.3 KB)

@jasperlzx Is its possible to share the data in excel and specify what you are looking in that?

sorry I canā€™t share the file. I just need to location the word, ā€œemployee nameā€, and take the 6 rows till the next ā€œemployee nameā€. thanks.

@jasperlzx Here you go SearchDataTable.zip (7.8 KB)

Hi some one help me to do the same for a number instead a word for the above case. i used filter wizard and able to achieve this. but i would like to try with For each and if. Example : student record. specific column name : Age.
for all the rows where age is more than 10 , then a specific sequence need to get executed.

I created variable as ā€œAgeā€ data type string. then if condition didnā€™t allow to use Age>10. since 10 is different data type.

If i use int32 or double same error while comparing in IF

if you are trying to compare within the for each loop, try checking
(Convert.ToInt32(row(ā€œAgeā€).ToString) > 10)

1 Like

Hi how would I sort if I am just looking for rows that Start with 4 Alphanumeric charcters

this worked :slight_smile: