Assign: Exception has been thrown by the target of an invocation.DataTable_Error

Hi All,

I am facing a challenge in error “Assign: Exception has been thrown by the target of an invocation.”

I am trying to scrape the data using Table extraction and remove the first row of a Data Table and making the second row as column header .I am getting the Table Table as column number in first row instead of column name. I am trying to remove the first row.

I am extracting the DataTable and using a For Each Loop. Then using an assign activity

currentitem.ColumnName= ExtractDataTable_CreditMemo.Rows(0)(currentitem.ColumnName).ToString

and finally deleting the first row,

ExtractDataTable_CreditMemo= ExtractDataTable_CreditMemo.AsEnumerable.skip(1).CopyToDataTable


image

@dutta.marina Run it in debug to see what the datatable & your variables contain.

currentitem is not a column. It’s just an item in a string array.

If you’re trying to rename a column you need to do…

ExtractDataTable_CreditMemo.Columns(index or column name).ColumnName

instead of currentitem.ColumnName

Hi Paul,

The same way I did for previous data table. I tried to remove first row and the second row became header or column name. There was no error .


item.ColumnName= ExtractDataTable_Invoice.Rows(0)(item.ColumnName).ToString

ExtractDataTable_Invoice= ExtractDataTable_Invoice.AsEnumerable.Skip(1).CopyToDataTable

In your For Each, did you change the TypeArgument to System.Data.DataColumn?

image

I’ve usually done this by using the .Columns array as an array of strings just to get the column names, then referencing the column by name on the left side of the Assign…but I guess it could work doing it the way you’re doing it as long as you have the For Each set up properly.

Hi @dutta.marina
Please check one thing. Your number of column and number of values present in first row. I believe when it comes to last column it founds issue because of corresponding empty value.

@dutta.marina

Please run in debug mode and then you can open the locals panel and see the exception details…which will contain the exact error which has occured…accordingly we can move forward

Cheers

sure Anil. Let me do that

1 Like