Sort data table by index Column using invoke code vb.net

Hi guys. As it says in the title, i have a data table dt1 which needs to be sorted using an index column indexColumn = 4 in an ascending order.
I used the Sort Data Table activity as below and it works fine.

input: dt1
output: dt2
index: indexColumn

But i wanna do this in an Invoke Code activity with vb.net.
What i’ve tried so far is the following:

dt1.DefaultView.Sort = indexColumn ASC
dt1 = dt1.DefaultView.ToTable()

But it throws error: disallows conversions from integer to string

That will take the column name and not its index, therefore you get that error…
Dim orderedby = From p As DataRow In dt.Rows Order By p.Item(4) Ascending

Thanks for your fast reply. The thing is that i need to use the indexColumn variable so how can i put it in your command line?

And also need to use dt2 which is the resulting data table after sorting dt1. Sorry forgot to mention!

where you see dt, you change to your data table variable name…

1 Like

that i understand but what about indexColumn variable which is int32. Where do i put that ?

Hi. Managed to find the below solution:

dt1.DefaultView.Sort = dt1.Columns(indexColumn).ColumnName + “ASC”
dt2 = dt1.DefaultView.ToTable

Thanks for the replies anyways :slight_smile:

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