Search code examples
sql-server-cedata-paging

Data paging in SQL Server CE (Compact Edition)


I am writing a wpf destop application, and would like to use SQL Server CE as a backend. I'm trying to come up with a good way to do efficient data paging. In SQL Server Express, I can do something like this:

Select ID, FirstName, LastName
From (SELECT  ROW_NUMBER() OVER (ORDER BY ID)
 AS Row, ID, FirstName, LastName
 From TestTable                             
) 
WHERE  Row > 1 AND Row <= 10    

Is there anything comparable in SQL Server CE? I'm not completely sure what is and is not supported. I want to only return 10 rows at a time from the database, and not have to pull back all the data and then filter it down to display to the user, since that is much slower. Thanks.


Solution

  • Honestly, probably the fastest thing to do is use an SqlCeDataReader and call .Read() 10 times. Then when the user moves to the next page, you're already pointing at the 11th result, and can read 10 more. If you need to go backwards, you can either cache your results or switch to an SqlCeResultSet which supports seeking.

    Also, SqlCeDataReader/Result is, from experience, the absolute fastest way to interact with the database on the desktop. It can be literally 100 times faster than using DataSets/DataAdapters.