How to change Datatable columns order in c#.
Example:
am created sql table type order is Qty,Unit,Id but in program DataTable order is Id,Qty,Unit. In code B
If you have more than 2-3 columns, SetOrdinal is not the way to go. A DataView's ToTable method accepts a parameter array of column names. Order your columns there:
SetOrdinal
ToTable
DataView dataView = dataTable.DefaultView; dataTable = dataView.ToTable(true, "Qty", "Unit", "Id");