views:

26

answers:

2

i have used this query to fetch the Record of the Datatable based on the Pagesize.

   IEnumerable<DataRow> query1 = from row in dt.AsEnumerable().Take(page_size).Skip(offset) select row;

Datatable boundTable= query1.CopyToDataTable();

first time when it opens the offset will be =0; it gives 10 records,

next time i pass the offset as 10 to get next ten records, but it is not giving any enum values. showing me a message says ' Enumeration yielded no results '

but the dt which i querying has nearly 1000 records. what wrong i made here...

+3  A: 

You're using Skip and Take in the wrong order. Try this:

IEnumerable<DataRow> query = dt.AsEnumerable()
                               .Skip(offset)
                               .Take(pageSize);

(I removed the query expression syntax as it wasn't doing you any favours here.)

You were doing Take then Skip - so you were saying something like, "Give me the first ten records, then skip to the eleventh of those ten." That's clearly not going to give you any results :)

The above says, "Skip to the eleventh record, then give me the first ten records that are left."

Jon Skeet
@Downvoter: Care to comment?
Jon Skeet
+2  A: 

Change the order of your Skip and Take. You're asking the query to Take 10 from the result set, then skip 10 - leaving none.

Stephen Newman