微軟的解決辦法
使用系統;
usingsystem.data;
usingsystem.data.sqlclient;
usingsystem.drawing;
Usingsystem.windows.forms;
uplyClassPagingsample:表格
{
// formcontrols。
buttonprevbtn = newbutton();
buttonnextbtn = newbutton();
staticdatagridmygrid = newdatagrid();
staticlabelpagelbl = newlabel();
// pagingvariables。
staticintpagesize = 10; // sizeofviewedpage。
staticinttotalpages = 0; // TotalPages。
staticintCurrentPage = 0; // CurrentPage。
staticstringfirstvisiblecustomer =; // first customeronpagetodeTermineLocationformovePrevious。
staticstringlastvisiblecustomer =; // lastcustomeronpagetodeTerminElocationformovenext。
// datasettobindtodatagrid。
靜態databablecusttable;
// initizeconnectiontodatabaseanddataadapter。
staticsqlConnectionNwindConn = newsqlConnection(dataSource = localhost; IntegratedSecurity = sspi; onitionCatalog = northwind);
staticsqldataAdapterCustda = newsqldataAdapter(,nwindconn);
staticsqlcommandselcmd = custda.SelectCommand;
publicStaticVoidGetData(StringDirection)
{
//創建QLSTATEMENTTORETRETNAPAGEOFRECORDS。
selcmd.parameters.clear();
開關(方向)
{
casenext:
selcmd.commandText = selecttop+pagesize+customerId,companynameFromCustomers+
wherecustomerid> @customeridorderbycustomerid;
selcmd.parameters.add(@customerId,sqldbtype.varchar,5).value = lastVisibleCustomer;
休息;
Caseprevious:
selcmd.commandText = selecttop+pagesize+customerId,companynameFromCustomers+
wherecustomerid <@customeridordorderbycustomeriddesc;
selcmd.parameters.add(@customerId,sqldbtype.varchar,5).value = firstVisibleCustomer;