How to change DataTable columns order

前端 未结 6 926
旧时难觅i
旧时难觅i 2020-12-02 07:46

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

6条回答
  •  时光取名叫无心
    2020-12-02 08:28

    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:

    DataView dataView = dataTable.DefaultView;
    dataTable = dataView.ToTable(true, "Qty", "Unit", "Id");
    

提交回复
热议问题