微软的解决办法
UsingSystem;
uesingsystem.data;
uesingsystem.data.sqlclient;
usingsystem.drawing;
uesingsystem.windows.forms;
publicClasspagingsample:form
{
// formcontrols。
ButtonPrevBtn = newButton();
buttonnextbtn = newbutton();
staticdatagridmygrid = newdatagrid();
staticlabelpagelbl = newLabel();
// pagingvariables。
staticIntPagesize = 10; // sizeofviewedpage。
StaticIntTotalPages = 0; // TotalPages。
StaticIntCurrentPage = 0; // currentPage。
StaticStringFirstVisiblecustomer =; // firstCustomeronPageTodEterminElocationFormovePrevious。
staticStringlastvisiblecustomer =; // lastcustomeronpageTodEterminelocationformovenext。
// datasetobindtodatagrid。
staticdatablecusttable;
// initializeconnectionTodatabaseanddataadapter。
staticsqlconnectionnwindconn = newsqlconnection(dataSource = localhost; integratedsecurity = sspi; initialCatalog = northwind);
staticsqldataadaptercustda = newsqldataadapter(、nwindconn);
staticsqlcommandselcmd = custda.selectcommand;
publicStaticVoidgetData(StringDirection)
{
// createSqlStatementToreturnapageOfRecords。
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 <@customeridorderbycustomeriddesc;
selcmd.parameters.add(@customerid、sqldbtype.varchar、5).value = firstVisiblecustomer;