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)
- Remove the empty row in datatable
- Choose the exact cells instead of choosing the collomn when remove duplicates which cause the empty row in my datatable
- 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!