-----------------------------------
Database write Stored Procedure
Create proc usp_pagesplit2 @ pageindex int, @ pagesize int, @ pagecount int output, @ records int outputasbeginselect @ pagecount = count (*) from DBO. sset @ records = ceiling (@ pagecount/@ pagesize) Select * from (select row_number () over (order by SnO DESC) as num, * From DBO. s) as twhere T. num between (@ pageIndex-1) * @ pagesize + 1 and @ pageindex * @ pagesize enddeclare @ PC int, @ RC intexec usp_pagesplit2 2, 2, 3, @ PC output, @ RC outputprint @ pcprint @ RC
-------------------------------------
Call in ADO
1 Private void storeproces_load (Object sender, eventargs E) 2 { 3 Getdata (1 ); 4 } 5 6 Private Int Pageindex = 1 ; 7 Void getdata ( Int Index ) 8 { 9 Sqlconnection Conn = New sqlconnection (@ "Server = . \ Sqlexpress; Database = Studentdb; uid = SA; pwd = 123456 "); 10 Sqlcommand comm = New sqlcommand ("usp_pagesplit2", Conn ); 11 // Sqlparameter [] Para = { 12 // New sqlparameter (" @ Pageindex ", Index ), 13 // New sqlparameter (" @ Pagesize ", 5 ), 14 // }; 15 Sqlparameter p1 = New sqlparameter (" @ Pageindex ", Index ); 16 Sqlparameter p2 = New sqlparameter (" @ Pagesize ", 3 ); 17 Sqlparameter p3 = New sqlparameter ("@ Pagecount ", Sqldbtype. Int ); 18 Sqlparameter p4 = New sqlparameter (" @ Records ", Sqldbtype. Int ); 19 20 Comm. parameters. Add (P1 ); 21 Comm. parameters. Add (P2 ); 22 Comm. parameters. Add (P3 ); 23 Comm. parameters. Add (P4 ); 24 25 P3.direction = Parameterdirection. output; 26 P4.direction = Parameterdirection. output; 27 28 Sqldataadapter SDA = New sqldataadapter (Comm ); 29 SDA. selectcommand. commandtype = Commandtype. storedprocedure; 30 // Comm. Parameters. addrange (para ); 31 32 Datatable dt = New datatable (); 33 SDA. Fill (DT ); 34 This. datagridview1.datasource = DT; 35 36 This. labpagecurrent. Text = Index + " / " + Comm. Parameters [ 3 ] . Value. tostring (); 37 } 38 39 Private void btnlast_click (Object sender, eventargs E) 40 { 41 Pageindex -- ; 42 If (Pageindex < 1 ) 43 { 44 Pageindex = 1 ; 45 } 46 Getdata (pageindex ); 47 } 48 49 Private void btnnext_click (Object sender, eventargs E) 50 { 51 Pageindex ++ ; 52 If (Pageindex > 3 ) 53 { 54 Pageindex = 1 ; 55 } 56 Getdata (pageindex ); 57 }