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:
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";
dt.DefaultView.Sort = dt.Columns[index].ColumnName + " DESC";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With