如何对具有多个排序条件的数据集 VB.NET 中的列进行排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20239281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:58:04  来源:igfitidea点击:

How to sort a column in dataset VB.NET having multiple sort conditions

vb.netsortingdatasetdefaultviewcolumnsorting

提问by Himanshu

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

我有一个数据集,其中有一列包含各种字符串类型值,如下所示:

Aircraft Crime Package Total Apartments DIC - Personnel

飞机犯罪套餐 Total Apartments DIC - 人员

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”值,则它必须位于数据集的顶部位置,之后所有其他值应按字母顺序排序,如下所示:

Package Total Aircraft Apartments Crime DIC - Personnel

包 Total Aircraft Apartments 犯罪 DIC - 人员

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:

我们在数据库中使用了下面的逻辑,它工作正常,但无法弄清楚如何从 Fronend 端在 Dataset VB.net 上做到这一点:

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!

任何回复/想法都会有所帮助!

回答by Hoh

Something like this might work for you:

像这样的事情可能对你有用:

    DataView dv = sDataSet.Tables("Table1").DefaultView;
    dv.Sort = "column1";

回答by Sudhakar MuthuKrishnan

YourDatasourceName.YourDatasetName.DefaultView.Sort = "YourColumnName"

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