DataTable Sort using column number instead of column names
.net, c#, performance
Solution
Try this method:
dt.DefaultView.Sort = sortColumn;
dt = dt.DefaultView.ToTable();
instead of
`sortColumn = "3 desc, 4 desc";`
you can use
`sortColumn = dt.Columns[3].ColumnName + " DESC," + dt.Columns[4].ColumnName + " DESC";`
Problem
I would like to sort a datatable by using the column index not with column names. I am be able to do this with SQL by using `ORDER BY 2` or `ORDER BY 3 DESC, 4 DESC`.But for DB performance issues I would like to do this by using CPU performance. So how do I do that in c# ? Example, which is not works for me: ``` sortColumn = "3 desc, 4 desc"; dt.DefaultView.Sort = sortColumn.ToString(); dt = dt.DefaultView.ToTable(); ```