In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "mssql access database using top paging method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "mssql access database using top paging method" bar!
The copy code is as follows:
Uusing system.collections.generic;sing system;using system.text / the sql statement after paging is constructed / public static class paginghelper {/ get the paging sql statement. The sorting field needs to form a unique record / total number of records / records per page / current pages / sql query statement / sort field Multiple paging sql statements public static string createpagingsql (int _ recordcount, int _ pagesize, int _ pageindex, string _ safesql, string _ orderfield) {/ / recombine sorting fields with "," to prevent errors string [] arrstrorders = _ orderfield.split (new char [] {','}, stringsplitoptions.removeemptyentries) Stringbuilder sboriginalorder = new stringbuilder (); / / original sort field stringbuilder sbreverseo tutorial rder = new stringbuilder (); / / contrary to the original sort field, it is used for paging for (int I = 0; I
< arrstrorders.length; i++) { arrstrorders[i] = arrstrorders[i].trim(); //去除前后空格 if (i != 0) { sboriginalorder.append(", "); sbreverseorder.append(", "); } sboriginalorder.append(arrstrorders[i]);int index = arrstrorders[i].indexof(" "); //判断是否有升降标识 if (index >0) {/ / replace the ascending and descending flag, bool flag = arrstrorders [I] .indexof ("desc", stringcomparison.ordinalignorecase)! =-1; sbreverseorder.appendformat ("{0} {1}", arrstrorders [I] .remove (index), flag? "asc": "desc");} else {sbreverseorder.appendformat ("{0} desc", arrstrorders [I]);}} / / calculate the total number of pages _ pagesize = _ pagesize = = 0? _ recordcount: _ pagesize; int pagecount = (_ recordcount + _ pagesize-1) / _ pagesize;// check the current number of pages if (_ pageindex)
< 1) { _pageindex = 1; } else if (_pageindex >Pagecount) {_ pageindex = pagecount;} stringbuilder sbsql = new stringbuilder (); / / on the first page, use top n directly without paging query if (_ pageindex = = 1) {sbsql.appendformat ("select top {0} *", _ pagesize); sbsql.appendformat ("from ({0}) as t", _ safesql); sbsql.appendformat ("order by {0}", sboriginalorder.tostring ()) } / / reduce one top n else if (_ pageindex = = pagecount) {sbsql.append ("select * from"); sbsql.append ("("); sbsql.appendformat ("select top {0} *", _ recordcount-_ pagesize * (_ pageindex-1)); sbsql.appendformat ("from ({0}) as t", _ safesql); sbsql.appendformat ("order by {0}", sbreverseorder.tostring ()) Sbsql.append (") as t"); sbsql.appendformat ("order by {0}", sboriginalorder.tostring ()); else if (_ pageindex < (pagecount / 2 + pagecount% 2)) {sbsql.append ("select * from"); sbsql.append ("("); sbsql.appendformat ("select top {0} * from", _ pagesize); sbsql.append ("(") Sbsql.appendformat ("select top {0} *", _ pagesize * _ pageindex); sbsql.appendformat ("from ({0}) as t", _ safesql); sbsql.appendformat ("order by {0}", sboriginalorder.tostring ()); sbsql.append (") as t"); sbsql.appendformat ("order by {0}", sbreverseorder.tostring ()); sbsql.append (") as t"); sbsql.appendformat ("order by {0}", sboriginalorder.tostring ()) } / / Page else {sbsql.appendformat ("select top {0} * from", _ pagesize); sbsql.append ("("); sbsql.appendformat ("select top {0} *", (_ recordcount% _ pagesize) + _ pagesize * (pagecount-_ pageindex)); sbsql.appendformat ("from ({0}) as t", _ safesql); sbsql.appendformat ("order by {0}", sbreverseorder.tostring ()) Sbsql.append (") as t"); sbsql.appendformat ("order by {0}", sboriginalorder.tostring ());} return sbsql.tostring () } / get the total number of records / limit the number of records / sql query statement / the total number of records sql statement public static string createtopnsql (int _ n, string _ safesql) {return string.format ("select top {0} * from ({1}) as t", _ n, _ safesql) } / get the total number of records sql statement / sql query statement / total number of records sql statement public static string createcountingsql (string _ safesql) {return string.format ("select count (1) as recordcount from ({0}) as t", _ safesql) }} Thank you for your reading, the above is the content of "mssql access database using top paging method". After the study of this article, I believe you have a deeper understanding of the problem of mssql access database using top paging method, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.