微软的解决办法
usingSystem;
usingSystem.Data;
usingSystem.Data.SqlClient;
usingSystem.Drawing;
usingSystem.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.
//DataSettobindtoDataGrid.
staticDataTablecustTable;
//InitializeconnectiontodatabaseandDataAdapter.
staticSqlConnectionnwindConn=newSqlConnection(DataSource=localhost;IntegratedSecurity=SSPI;InitialCatalog=northwind);
staticSqlDataAdaptercustDA=newSqlDataAdapter(,nwindConn);
staticSqlCommandselCmd=custDA.SelectCommand;
publicstaticvoidGetData(stringdirection)
{
//CreateSQLstatementtoreturnapageofrecords.
selCmd.Parameters.Clear();
switch(direction)
{
caseNext:
selCmd.CommandText=SELECTTOP+pageSize+CustomerID,CompanyNameFROMCustomers+
WHERECustomerID>@CustomerIdORDERBYCustomerID;
selCmd.Parameters.Add(@CustomerId,SqlDbType.VarChar,5).Value=lastVisibleCustomer;
break;
casePrevious:
selCmd.CommandText=SELECTTOP+pageSize+CustomerID,CompanyNameFROMCustomers+
WHERECustomerID<@CustomerIdORDERBYCustomerIDDESC;
selCmd.Parameters.Add(@CustomerId,SqlDbType.VarChar,5).Value=firstVisibleCustomer;