Select TOP 5 * from SomeTable, using Dataview.RowFilter?

后端 未结 2 1967
死守一世寂寞
死守一世寂寞 2021-01-06 16:46

I need to select 5 most recent rows from cached Dataview object, is there any way to do that?

I\'ve tried but Indexer DataColumn is empty. :

public          


        
相关标签:
2条回答
  • 2021-01-06 17:21

    I encountered the same sample above in this article, but the last post says the provided code doesn't work.

    However, this article has a solution that does work, so here's the code you could use:

    public static DataView getLatestFourActive() {
        DataTable productDataTable = getAll().ToTable();
        DataTable cloneDataTable = productDataTable.Clone();
    
        for (int i = 0; i < 4; i++) {
            cloneDataTable.ImportRow(productDataTable.Rows[i]);
        }       
        return new DataView(cloneDataTable);
    }
    
    0 讨论(0)
  • 2021-01-06 17:32
    getALL().Take(5);
    
    0 讨论(0)
提交回复
热议问题