c# - Displaying Last 10 rows for first page than next last 10 rows for next page -
i using function displaying data in datagridview using paging ,using on page 1
getting last 10 rows displayed ,but when click on next button should display next last 10 rows
display top 10 rows on each next page ,i think mistake in cmd2 query of else part
? using access database
private datatable getcurrentrecords(int page, oledbconnection con) { dt = new datatable(); if (page == 1) { cmd2 = new oledbcommand("select top " + pagesize + " qid,question,opt1,opt2,opt3,opt4,ansop,marks questions order qid desc", con); // currentpageindex++; } else { int previouspagelimit = (page - 1) * pagesize; cmd2 = new oledbcommand("select top " + pagesize + " qid,question,opt1,opt2,opt3,opt4,ansop,marks questions " + "where qid not in " + "(select top " + previouspagelimit + " qid questions order qid desc) ", con); // + //"order medicalclgid", con); } try { // con.open(); this.adp1.selectcommand = cmd2; this.adp1.fill(dt); txtpaging.text = string.format("{0} of {1} ", this.currentpageindex, this.totalpage); } { // con.close(); } return dt; }
you can realize paging over() @ t-sql
select * ( select row_number() on ( order task_id ) rownum, qid,question,opt1,opt2,opt3,opt4,ansop,marks [questions] ) rowconstrainedresult rownum >= 10 , rownum < 20 order rownum
Comments
Post a Comment