Assign: Unable to cast object of type 'System.Int32' to type 'System.String'

Hello
I have a datatable: dt_OutputTable3 with one column like this:
Company
ABCD
ABCD
ABBB
ABCE
ABCE
EEEE

Now i build another datatable dt_OutputTable2 with two columns: Company (String) and Count (INT)

I would like a table with the individual companies and how often they occur.

I use assign activity:
dt_OutputTable2 =
(From row In dt_OutputTable3.AsEnumerable()
Group row By Unternehmen = row.Field(Of String)(“Unternehmen”) Into Group
Select dt_OutputTable2.Rows.Add(Unternehmen, Convert.ToString(Group.Count()))).CopyToDataTable()

With this i keep getting the following error message:
Assign: Unable to cast object of type ‘System.Int32’ to type ‘System.String’.

dt_OutputTable2 should look like this at the end:
Company Count
ABCD 2
ABBB 1
ABCE 2
EEEE 1

Can someone help me?

Thanks a lot!!

Hi @morseil

Can you try the below syntax:

dt_OutputTable2 =
    (From row In dt_OutputTable3.AsEnumerable()
     Group row By Unternehmen = row.Field(Of String)("Unternehmen") Into Group
     Select dt_OutputTable2.Rows.Add(Unternehmen, Group.Count())).CopyToDataTable()

Hope it helps!!
Regards

thanks! But I keep getting the same error message… :neutral_face:

@morseil
What does it column Unternehmen contain.

Regards

@morseil

You have declared the column type as int for count…and in your formula you are converting it to string…

Remove convert.ToString from your code

Cheers