/// <summary>///use virtual tables for paged queries that do not apply to queries that explicitly know the column name/// </summary>/// <param name= "SQL" >SQL such as "SELECT * from name where 1=1"</param>/// <param name= "PageIndex" >page number such as "1"</param>/// <param name= "PageSize" >the number of bars, such as "</param>/// <returns>DataTable</returns> Public StaticDataTable selectpaging (String sql,intPageIndex,intpageSize) { //Defining virtual table names stringTemporarytable ="#"+randstring (); //Create your virtual tables stringSqlpaging ="Select Identity (int) as ZZZZZ, * into"+ temporarytable +"From (select TOP Percent * FROM ("+ SQL +") a) a"; //using virtual tables for paged queriesSqlpaging + ="SELECT * from"+ temporarytable +"a WHERE 1=1"+"and a.zzzzz >="+ PageIndex * pageSize +"and a.zzzzz <="+ ((PageIndex +1) * PageSize-1) +" "; //Delete a virtual tableSqlpaging + ="DROP TABLE"+temporarytable; //Execute SQL statement selectcustomsql to execute SQL method you need to define yourselfDataTable dt =Selectcustomsql (sqlpaging); //determines whether the returned result is empty if(dt! =NULL) { //Remove an identity columnDt. Columns.remove ("zzzzz"); } //return Results returnDT;}
Other paging methods Baidu on more.
SQL Server Paging method