How to deal with the foreach error with an empty row in datatable


#1

I’m doing the vlookup of excel and use the foreach and always show a error “Objective reference not set to an instance of an object.” I check my codding and find there is a empty row in my datatable used to do the foreach after removing duplicates. Because of the empty row, when the loop goes to this row, it will show error. To solve this problem. I think there are several ways. (may not be correct)

  1. Remove the empty row in datatable
  2. Choose the exact cells instead of choosing the collomn when remove duplicates which cause the empty row in my datatable
  3. During the Foreach, when no value send to the variable. Go for the next row and continue the loop.
    Can anybody help me to check my judgment to this error and explain any of the solutions in detail? Thank you very much!

#2

Hello.

Can you attach the workflow. It might be faster just to give you an example wf.


#3

A simple question is that how to remove duplicates in database without a empty row


#4

Here is an example with removing identical rows. If you need to remove rows based on a certain column value it might be a little more difficult.

RemoveDuplciateRows.xaml (8.3 KB)


#5

Not more difficult , simplest way may be to use "Get row item " in datatable for-each with a property of ‘ColumnName’ and by using that return value and if condition on true use Remove Data Row activity.

Regards…!!
Aksh


#6

It works! Thank you very much


#7

Hello, I would be very interested to know how to solve "3. During the Foreach, when no value send to the variable. Go for the next row and continue the loop."
Does anyone have the solution ?


#8

aksh1yadav,

Would you be able to go into further detail on how to accomplish this? Specifically, how to use a return value in a “get row item” as well as what expressions to use in the if conditions. Also, how would I use the “remove data row” to remove the duplicate value for the cell?


#9

Hi Akshay, when I am using for each row in a data table, if row contains nothing or “” it is throwing error as null reference error, how to avoid this .


#10

sorry bro I got it