none
How to select the first N rows of a datatable? RRS feed

  • Question

  • Greetings,

     

    It must be easy, but I still have not found a way to do it.

     

    The code I have:

     

            DataTable values = (new PaymentDB()).DailyTotalAllHorizontal();
            var query =
                from value in values.AsEnumerable()
                orderby value.Field<DateTime>("MONTH") descending
                select value;
            DataView dv = query.AsDataView();

    But I only want to have the first N rows in dv, not all of the rows of values. How may I do it?

     

    Thanks

    Tuesday, April 22, 2008 8:11 AM

Answers

  • @Robert

     

    I could not get .AsDataView() to work for me.

     

    I am using .CopyToDataTable(), and it works!

     

    Thanks!

    Wednesday, May 14, 2008 9:03 AM

All replies