Help with this invoke code

Hello Guys,
Just before i give up on this method :smile:, i just want to post it here just in case someone sees what i am doing wrong.
I have this code to get the sum of items in a particular on a datatable and it works fine. No what i want to do is simply create a row at the end of my data table and write this sum in column 5 of that new row.
I am trying to achieve this in one invoke code…
and here is what i have but it doesn’t work

Dim AmountSum As String = dtInput.AsEnumerable.Sum(Function(x) Convert.ToDouble(x(in_TransactionAmountColumn).ToString.Trim) ).ToString
Console.WriteLine(AmountSum)

dtInput.Rows.Add(in_NumberOfEntries + 1)
dtInput.Rows(in_NumberOfEntries + 1).Item(in_TransactionAmountColumn)= AmountSum

where in_NumberOfEntries is the count of rows of the datatable before the introduction of the new row.
The code for the amount sum works, but the add data row and write to new data row is not working

Thanks

Hi @MasterOfLogic , You have not added new data row, You can simply use " Add Data Row" activity. Hope this helps

Hi @MasterOfLogic

Can you explain more on what is the error you are getting or whether your workflow is executing but not giving you the correct result?

Can you share your owrkflow?

Hi @MasterOfLogic

If you are getting the Sum Correct then after that you can use Assign Activity for to get he Row Count.

And then using Write Cell Activity within Properties you can pass Range as below :-

“A”+(CountOfRow+1).ToString

Note :- Instead of A you have to give the Alphabet of the column in which you have to write the Sum

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

This is wrong use of the Add method. You should do it as follows:

Dim R As DataRow = dtInput.NewRow
R("your_column_name") = AmountSum
dtInput.Rows.Add(R)

Cheers

1 Like

This worked !! Exactly what i wanted to do