Invoke Code: Exception with DT

Hey
I am trying to add 2 rows in a dt.
First one should be empty.
Second one should have sums of some specific columns.
When trying to invoke a vb code I get the error message from the subject title.

Here is the code in text form:

in_dtEingang.Rows.Add()

Dim sumColumn6 As Double = 0
Dim sumColumn7 As Double = 0
Dim sumColumn10 As Double = 0

For Each row As DataRow In in_dtEingang.Rows
sumColumn6 += Convert.ToDouble(row(6))
sumColumn7 += Convert.ToDouble(row(7))
sumColumn10 += Convert.ToDouble(row(10))
Next

in_dtEingang.Rows(in_dtEingang.Rows.Count - 1)(6) = sumColumn6
in_dtEingang.Rows(in_dtEingang.Rows.Count - 1)(7) = sumColumn7
in_dtEingang.Rows(in_dtEingang.Rows.Count - 1)(10) = sumColumn10

Am I doing something wrong with the arguments?
Are the changes in the invoke code only changing the in_dtEingang or also effecting the dt_Eingang?
How would i get the edited dt out of the invoke code?

We can avoid invoke code Black boxing by

Summing up col values with LINQ within Assign activity

Then assigning it to the last row by
Assign Activity
dtVar.AsEnumerable.Last()(ColNameOrIndex) = YourSum

1 Like

Hi @Tmsn

Can you share the sample input and expected output for that.

Regards

1 Like

as a variation:
Assign Activity:
sum6 = dtVar.AsEnumerable().Sum(Function (x) Convert.ToDouble(x(6)))
… same for 7 and 10

Assign Activity:
drNew | Datarow = dtVar.NewRow

Assign Activity
drNew(6) = sum6
… same for 7 and 10

Add Row Activity adding drNew to dtVar

1 Like

[Rang,Artikel,Whrg,Einht,Referenzartikelhauptgruppe,in %,Menge,Brutto,Rabatt Betrag,Rabatt %,Netto,Ø Preis
1,81120Boden-Bauschutt Z1.2 < 50% Bauschutt,EUR,t,40 Baurestmassen,0.6025966281675591,13478.7,211743.96,0,0,177936.04,13.2012760874565
]

This is one example input row

And the code should sum column 6,7 and 10 and add it

Nicht ganz klar, can it be rephrased?

This is the input/what’s in dt_eingang

Its only one datarow and not 10+ as in the real case.

But after multiple rows it should add one row and sum specific columns

done with:

preparing add row

done with

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.