时间:2021-05-18
微软的解决办法
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)
{
case"Next":
selCmd.CommandText="SELECTTOP"+pageSize+"CustomerID,CompanyNameFROMCustomers"+
"WHERECustomerID>@CustomerIdORDERBYCustomerID";
selCmd.Parameters.Add("@CustomerId",SqlDbType.VarChar,5).Value=lastVisibleCustomer;
break;
case"Previous":
selCmd.CommandText="SELECTTOP"+pageSize+"CustomerID,CompanyNameFROMCustomers"+
"WHERECustomerID<@CustomerIdORDERBYCustomerIDDESC";
selCmd.Parameters.Add("@CustomerId",SqlDbType.VarChar,5).Value=firstVisibleCustomer;
break;
default:
selCmd.CommandText="SELECTTOP"+pageSize+"CustomerID,CompanyNameFROMCustomersORDERBYCustomerID";
//Determinetotalpages.
SqlCommandtotCMD=newSqlCommand("SELECTCount(*)FROMCustomers",nwindConn);
nwindConn.Open();
inttotalRecords=(int)totCMD.ExecuteScalar();
nwindConn.Close();
totalPages=(int)Math.Ceiling((double)totalRecords/pageSize);
break;
}
//Fillatemporarytablewithqueryresults.
DataTabletmpTable=newDataTable("Customers");
intrecordsAffected=custDA.Fill(tmpTable);
//Iftabledoesnotexist,createit.
if(custTable==null)
custTable=tmpTable.Clone();
//Refreshtableifatleastonerecordreturned.
if(recordsAffected>0)
{
switch(direction)
{
case"Next":
currentPage++;
break;
case"Previous":
currentPage--;
break;
default:
currentPage=1;
break;
}
pageLbl.Text="Page"+currentPage+"of"+totalPages;
//Clearrowsandaddnewresults.
custTable.Rows.Clear();
foreach(DataRowmyRowintmpTable.Rows)
custTable.ImportRow(myRow);
//Preservefirstandlastprimarykeyvalues.
DataRow[]ordRows=custTable.Select("","CustomerIDASC");
firstVisibleCustomer=ordRows[0][0].ToString();
lastVisibleCustomer=ordRows[custTable.Rows.Count-1][0].ToString();
}
}
publicPagingSample()
{
//Initializecontrolsandaddtoform.
this.ClientSize=newSize(360,274);
this.Text="NorthWindData";
myGrid.Location=newPoint(10,10);
myGrid.Size=newSize(340,220);
myGrid.AllowSorting=true;
myGrid.CaptionText="NorthWindCustomers";
myGrid.ReadOnly=true;
myGrid.AllowNavigation=false;
myGrid.PreferredColumnWidth=150;
prevBtn.Text="<<";
prevBtn.Size=newSize(48,24);
prevBtn.Location=newPoint(92,240);
prevBtn.Click+=newEventHandler(Prev_OnClick);
nextBtn.Text=">>";
nextBtn.Size=newSize(48,24);
nextBtn.Location=newPoint(160,240);
pageLbl.Text="NoRecordsReturned.";
pageLbl.Size=newSize(130,16);
pageLbl.Location=newPoint(218,244);
this.Controls.Add(myGrid);
this.Controls.Add(prevBtn);
this.Controls.Add(nextBtn);
this.Controls.Add(pageLbl);
nextBtn.Click+=newEventHandler(Next_OnClick);
//PopulateDataSetwithfirstpageofrecordsandbindtogrid.
GetData("Default");
DataViewcustDV=newDataView(custTable,"","CustomerID",DataViewRowState.CurrentRows);
myGrid.SetDataBinding(custDV,"");
}
publicstaticvoidPrev_OnClick(objectsender,EventArgsargs)
{
GetData("Previous");
}
publicstaticvoidNext_OnClick(objectsender,EventArgsargs)
{
GetData("Next");
}
}
publicclassSample
{
staticvoidMain()
{
Application.Run(newPagingSample());
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
yii的分页类CLinkPager默认是不支持显示共x页的,那么现在需求来了,要在分页的后面显示共多少页,怎么办喃?我们来看解决办法1、默认的CLinkPage
首先先看问题:在开发的时候,看到这种现象就会思考:为什么左边的数据出来比右边的慢呢?因为这里没有进行分页,左边的数据多,所以查询相对较慢。解决办法就是进行分页,
解决办法:列表页分页代码:复制代码代码如下:{dede:pagelistlistitem="info,index,end,pre,next,pageno,opt
Springboot启动项目后网页显示【Pleasesignin】遇到的情况解决办法解决效果根本原因(依赖导错了)根本解决办法遇到的情况启动SpringBoot
首先明确为什么要使用分页查询,因为数据庞大,查询不可能全部显示在页面上,如果全部显示在页面上,也会造成查询速度慢的情况,所以分页查询解决了①数据查询;②性能优化