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();
Try this method:
instead of
sortColumn = "3 desc, 4 desc";you can use
sortColumn = dt.Columns[3].ColumnName + " DESC," + dt.Columns[4].ColumnName + " DESC";