How to perform string operations on a selected rowItem using foreach Loop datatable

excel
uiautomation

#1

Hi All,

I am trying to perform string operations on a rowitem selected using Foreach loop for Datatable. But it throws exception saying generic .Net error message “Object Reference Not set to an instance of object”.\

** I am doing MS Excel file reading operations **

I have already tried changing object type/variable type, but its a waste.
Thanks in advance!


How to get the datablerow
#2

Hello!

Can you post the command that you’re trying to do and It’s getting the error?

Regards,


#3

Hi @devansh,

I have created an example that do some operations with String and Int variable types and use the For each row activity to iterate between the rows from a specific data table.

Main.xaml (10.2 KB)

Kindly check and tell us if it’s what you were expecting.


How to read Calendar in graphic form?
#4

Did you check if the DataTable has rows?


#5

Hi @vvaidya,

When there aren’t rows in the data table, the operations inside the For each row activity don’t execute, then it wouldn’t be a problem because it only enters into this activity when there are rows in the data table.


#6

You are right…inside the foreach most commonly you will see Index out of range exception.


#7

Hi,
I am doing MS excel file related activity… which is doing simple read the xl --> save it in a Datatable --> Iterate through all rows and --> write the rowitem.

This While iterating rowitem using get row item activity, it is throwing exception of Null reference… Hence I can not perform any operation eg. convert to string, convert to int, split, substrings etc


Loop through a data table
#8

Try to do it like this:

row.Item(columnNumber).ToString()

Once inside the For Each you can take the data without using ‘Get Row Item’ activity. Make sure that the row has values or will throw a exception.


#9

Hi @devansh,

You may also try the following:

Main.xaml (9.1 KB)


#10

Thank You Lucas… for this solution.
I have solved the problem by using this as well : row(0).ToString


#11

hey there,

I have a data table in the browser and I want to loop thorugh it to search for a specific value in every row.
Unfortunately I have now download option for the table.

Is there any option to use the for each activity to loop thorugh the list and/or to store the whole list as a datatable variable?