But I feel the error is with the variable Yourdatatablename
Check whether it is a datatable or some other variable type
Change the type of that variable and give a try
Hi
and thank you all for the quick responses! It was indeed a wrong datatype for the datatable, my bad
However this is just one step of what I want to get: I want to extract something like a dictionary that consists of keys each one representing the occurence of a certain element in the column and the corresponding value being an int32 array, that contains all the indices of the rows, in which the key value appears in the column.
Example for column4:
…should result in a dictionary of:
{{“element1”, {0,1,5}},
{“element2”, {2,6,8}},
{“element3”, {3,4,7}}}
Is there a better and quicker way than iterating through all the rows in a for loop for getting the int32 arrays?
dt = dt.AsEnumerable.Select(Function(r,i)
If (Not dict.ContainsKey(r("col4").ToString)) Then
dict.Add(r("col4").ToString,New List(Of Int32))
End If
dict(r("col4").ToString).Add(i)
Return r
End Function
).CopyToDataTable