1

I have a dataset in which there is a column contains various string type values like below:

Aircraft Crime Package Total Apartments DIC - Personnel

Now the requirement is that after applying sorting logic on this colum if there is a "Package Total" value in it then it must come at the top position on the Dataset and after that all other values should be in alphabatically sorted order like below:

Package Total Aircraft Apartments Crime DIC - Personnel

We have used in Database below logic which is working fine but can't figure it out how to do it on Dataset VB.net from Fronend side:

ORDER BY 
CASE WHEN UseCarrierAllocation = 0 THEN 
    CASE WHEN InvoiceItemLevel LIKE 'Package Total%' THEN 0 ELSE 1 
    END 
END, InvoiceItemLevel ASC

Any reply/idea will be helpful!

Himanshu
  • 2,251
  • 4
  • 20
  • 25

2 Answers2

1

Something like this might work for you:

    DataView dv = sDataSet.Tables("Table1").DefaultView;
    dv.Sort = "column1";
Hoh
  • 1,196
  • 1
  • 12
  • 30
  • Thnaks for you reply but it won't work... as it requires conditional sorting. your suggestion will work only for single condition sort. – Himanshu Nov 27 '13 at 12:37
  • 1
    Can you please give an example/sample of how to do looping/for-each in this scerario. I have this dataset table with various columns and one of the column is "InvoiceItemLevel" which i have mentioned with various values. So i need to sort that dataset table using multiple condition like i have said i need package line first then all in alphabetical order. – Himanshu Nov 28 '13 at 11:15
  • Use ToTable. Example: For Each myRow As DataRow In dv.ToTable.Rows – Jeff Apr 29 '16 at 15:05
0
YourDatasourceName.YourDatasetName.DefaultView.Sort = "YourColumnName"

YourDataTableName = YourDatasourceName.YourDatasetName.DefaultView.ToTable(True, "YourColumnName")