How to fetch "Column Names" from Datatable using "For each row" activity?

Hi everyone.

I am able to fetch column names using “for each” activity from datatable.

I am unable to achieve the same using “for each row” activity from datatable.

I cant use “for each” activity now. Can someone please help me with this?

(Also please mention library name, if i need to import any)

Thank you,
Mahesh Gunda

Whenever you work on Datatables, you have to use “FOR EACH ROW”
To extract Column names you use Assign Activity and assign the column to variable
“DatatableName.Columns(0).toString()”
Column starts from 0
You can have logic to read columns dynamically say for example last row of excel
then you can use count of the columns and subtract it by 1, it will fetch you last column

5 Likes

Thank you @Mihir_Mapara

Will surely try it.

I want the bot to capture to column name when a blank cell is encountered as an exception in catch block. Is it possible?

Thank you.

Yes, it is possible @Mahesh_Gunda
Use If activity to check for blank cell and then use “Throw” activity if condition is satisfied
e.g :-
if (row.Item(“ColumnName”).ToString) = “”
then
Throw
else
do all your processing

Hope this solves your query

Cheers

@Mahesh_Gunda
Not knowing all your requirements by taking the trigger:

I want the bot to capture to column name when a blank cell is encountered as an exception in catch block.

we can map to the interrest of getting all column names of blanks within a row

With an IndexOf Approach the first occurence will be returned, other blanks are not transported. A LINQ help us to get all information:

checking if there a blanks in the row:
row.ItemArray.Any(Function (x) String.IsNullOrWhiteSpace(x.toString))

Getting a string array with the column names:
row.ItemArray.ToList.Select(Function (x, index) New Tuple(Of Int32, String)(index,x.toString)).Where(Function (t) String.IsNullOrWhiteSpace(t.Item2)).Select(Function (t) row.Table.Columns(t.Item1).ColumnName).ToArray

so a table with:
grafik

can be analyzed with code from above and a result could be:
grafik

find starter help here:
ColumnNamesForBlanks.xaml (8.5 KB)

2 Likes

can you help to check only slected cloumns are empty? and collect cloumns which are empty