Getting error msg when try to Add Data Row into a data table

I am trying to extract data from an excel file, according to a specific condition and then store it in another excel file.

  1. I am able to read all data from the ‘Companies Dataset’ excel file and store it to a data table.
  2. Using For Each Row from data table and using the If condition, I then try to Add Data Row in a new data table. But at this point I am getting error msg.- Add Data Row: Object reference not set to an instance of an object.
    image Img2 Img3

My goal is to copy only selected data into a new excel file.


@kapurnick, Try one of the following options:
Option 1: Set default value for outputDataFile2 as “new DataTable()”
Option 2: Use Assign Activity to initialize data table.
E.g. outputDataFile2 = new DataTable()

1 Like

I am getting same error msg. if I try the above Option 1 and Option 2.

Can you show us were is set data_row? Maybe your intention is just to pass row in your AddDataRow activity?

I don’t have set data_row in my process. Yes I was just thinking to pass a selected row which match my if condition in AddDataRow activity.

That’s why you have this error. Rename it row and you’ll be fine.

By the way, you can filter the datatable that way directly without a loop:

outputDataFile2 = readDataFile1.Select("Country='USA', [Value(USD)]=0").CopyToDataTable()

replace the 0 by the value searched.

Are you saying that in AddDataRow activity I simply change DataRow value to ‘row’ instead of ‘data_row’?
I did try to change but still I am getting same error msg.

Before your ForEach, add the following Assign:

outputDataFile2 = readDataFile1.Clone()

Still no luck.
After I find a row which matches my condition, how do I add it to a new data table and then write it to an excel file.

Now I am not getting "Object reference not set…’ error message but the excel file ‘OutputDataSet.xlsx’ only display headers without any data.

Here is how I change my process.

  1. My first Excel Application Scope is still the same. There is no changes to it.
  2. Modified For Each Row routine - I removed Add Data Row activity and inserted a Sequence in it Build Data Table - ‘dtOutput’
  3. Added another Excel Application Scope - Excel - Write Range activity to write data from data table ‘dtOutput’ into excel file.

Hi @kapurnick,

After your Excel Application Scope, can you try doing the following?

  1. Call Multiple Assign activity
  2. Set outputDataFile2 = new DataTable
  3. Click Add then set outputDataFile2 = readDataFile1.Clone
  4. Inside your IF condition in the FOREACH activity, put Add Data Row
  5. Set DataTable as outputDataFile2 then set ArrayRow as row.ItemArray()

When you’re done, it should look like this:


… also, it might be useful to see your Condition.

Thank you so much for all your help. As per your above instructions, I was able to run my process and also generate a valid results.
@Bhavik_Solanki, @msan, @jcastro
Once again, I would like to thank each and every one for all your help.


1 Like