Data paging in SQL Server CE (Compact Edition)

前端 未结 5 1462
时光取名叫无心
时光取名叫无心 2021-01-11 12:56

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

5条回答
  •  清歌不尽
    2021-01-11 13:51

    I did implement custom paging for datagrid using SQL CE. I implemented method of using top in select statement and skipping records using subquery as discussed in above answer. But it works good with small amount of data. As the records grow in thousand the above methodology becomes less helpful and becomes slow in performance.

    I solved poor performance issue by using my own technique. What i did is i store id of first and last record on each page in variables.

    dim firstRecord=dt.rows(0)("id")
    

    and

    dim lastRecord=dt.Rows(dt.rows.count-1)("id")
    

    I initialise these variables after grid is binded for every page.

    If user click next button i fetch top(Pagsize) records from database greater than lastRecord If user click on previous button i fetch top(PageSize) records from database less than firstRecord. Also i order by Id desc in this case. And reorder datatable using dataview to asc before binding to datagrid.

    It made my paging most efficient. Though i had to put some extra effort for insert and delete of records cases. But i was able to handle that.

提交回复
热议问题