0

就像在 TSQL 中一样:

select * from aTable where (aCondition) order by AnIntegerField desc, ADateField 

如何使用以下方法对 DataTable 进行排序:

dt.AsEnumerable().OrderBy(--two conditions --)
4

1 回答 1

4

您将首先使用 OrderBy,然后使用ThenBy(升序)或ThenByDescending(降序)。

从微软文档:

    string[] fruits = { "grape", "passionfruit", "banana", "mango", 
                          "orange", "raspberry", "apple", "blueberry" };

    // Sort the strings first by their length and then 
    //alphabetically by passing the identity selector function.
    IEnumerable<string> query =
        fruits.OrderBy(fruit => fruit.Length).ThenBy(fruit => fruit);

或对于 VB(因为问题被标记为两者):

    ' Create an array of strings.
    Dim fruits() As String = _
        {"grape", "passionfruit", "banana", "mango", _
         "orange", "raspberry", "apple", "blueberry"}

    ' Sort the strings first by their length and then 
    ' alphabetically by passing the identity function.
    Dim query As IEnumerable(Of String) = _
        fruits _
        .OrderBy(Function(fruit) fruit.Length) _
        .ThenBy(Function(fruit) fruit)
于 2012-07-29T00:05:04.610 回答