Nested query solves paging Problems

Source: Internet
Author: User
Tags rowcount
In the current information society, information is the lifeline, and a large amount of information is stored in the database.
Dataset provides a good data method for data access, but because it is a data set in the memory, if the data in the data table is large, for example, hundreds of thousands, it occupies more than a dozen gigabytes of space, so the server's memory will be far from enough to meet the needs. If there are thousands of people simultaneously accessing the server, we can imagine the pressure of the server, or even crash. To reduce the pressure on the server, we can only control the amount of data it needs to call each time and only display a small amount of data. Therefore, paging is displayed and underlying data calls are used to determine paging, it is very important. This is the purpose of this Article, hoping to help you.
The purpose of nested query is to ensure the uniqueness of the data retrieved each time, and prevent excessive data entries from being retrieved under the same query conditions, it also prevents duplicate data on two pages. I have encountered these problems in practical applications, and I have wasted a few hours to explore them. I hope you will learn from them.

MySQL statement: Code
1 string strsql = "select f_id, f_name, f_address, f_directory, f_guid, f_commentdirectory, f_edittime, expires, f_uploadtime, f_photo, f_author, f_kind, f_size, f_uploadtime, f_viewer, f_commentary, f_grades from (select * From t_vidio order by f_edittime DESC limit 0, "+ startcount +") derivetbl order by f_edittime limit 0, "+ endcount + ") A order by f_edittime DESC ";

In SQL Server, top replaces limit. For example:

SQL code
11 string strsql = "select
22
33f_id, f_name, f_address, f_directory, f_guid, f_commentdirectory, f_edittime, f_photographytime, f_uploadtime, f_photo, f_author, f_kind, F
44
55_size, f_uploadtime, f_viewer, f_commentary, f_grades from (select top "+ end. tostring () +" * from (select top "+
66
77start. tostring () + "* From t_vidio" + "where f_status =" + status. tostring () + "order by f_edittime DESC) derivetbl order
88
99f_edittime) A order by f_edittime DESC ";

Data Binding: C # Main Code
1 Public void binddata (INT pagenum)
2 {
3 int start, end;
4 /**//**/
5/** // pagenum starts from 0, and pagesize is the data row displayed on each page
6 start = (pagenum + 1) * pagesize;
7 /**//**/
8/*** // obtain the total page number
9 int totalpage = clutility. getconvertintvalue (session ["totalpage"]);
10 int rowcount = clutility. getconvertintvalue (session ["rowcount"]);
11 if (pagenum + 1 <totalpage)
12 {
13 end = pagesize;
14}
15 else
16 {
17 // obtain the absolute value
18 end = math. Abs (rowcount-pagenum * pagesize );
19}
20
21 if (END = 0)
22 {
23 end = 1;
24}
25 datatable dtable = vidiomanager. getvidios (vidio. statusnormal, start, end );
26 if (dtable = NULL)
27 {
28 return;
29}
30 buttonabletouse (pagenum );
31 vidiogridview. datasource = dtable. defaultview;
32 vidiogridview. databind ();
33}

Simple Interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.