1. Topic: General Data paging in Asp.net environment (including Oracle, sqlserver, db2 ...)
A long time ago, I wanted to create a data paging component for a common point, but I had not had enough time to implement it. (Of course, it was mainly because of some difficulty, to process view status, return events, and self-painting ...), during the "11" period, I went to lie down with my girlfriend in Xiangxi. During the day, I went to sleep and had nothing to do at night. I had to eat local snacks. When I was bored, I Google a piece of Oracle Data paging, there is no complete example of Asp.net + Oracle Data paging. Otherwise, you may decide to create one by yourself.
2. Environment
IDE; vs2008 + ASP. net2.0 or 3.0 + Oracle9i
Oracle test data; more than 0.41 million entries
Bandwidth: China Netcom has 2 M bandwidth. In fact, tnnd only has more than 100 kb.
3. Principles
Use rownum of Oracle9i to get the data we want, 3.1
CopyCode The Code is as follows: public ienumerable getpagesqlbyoracle (string SQL, int startrowindex, int maximumrows, string orderby)
{
String sqlformat = string. format ("select * from (select rownum RN, pagetable. * From {0} pagetable where rownum <= {1}) Where rn> {2} ", SQL, startrowindex + maximumrows, startrowindex );
Return ydjworacleconn. retrivedataset (sqlformat). Tables [0]. defaultview;
}
Startrowindex indicates the start index, and maximumrows indicates the number of records on each page to be obtained.
Bind the paginated data to the objectdatasource component, as shown in figure
4. Results
4.1 Support multi-sorting, such as time, such as ID number
More than 4.2 million data records
4.3 single-condition query, the first time 1.547 seconds
4.4 second time, in 1.515 seconds
The third time is almost the same.
4.5 check the time when all 0.41 million pieces of data are queried at a time without any conditions
As you can see, 0.41 million data records are queried without conditions. The first query takes 1.265 seconds.
4.6 You Can See That 0.41 million data records are queried without conditions. The second query takes 1.156 seconds.
4.7 can be replaced by sqlserver or a database such as DB2, you only need to modify the method for obtaining data in figure 3.1.
5. note:
5.1 When you remember that the data volume is tens of thousands, you must add an index. Otherwise, you have to wait for "Thank you ".
5.2 All parameter names of objectdatasource must be the same as the bound method parameter names in the same order.
5.3 if the cache can be used, try to use the cache
5.4's paging algorithm, replace the 3.1 method.
5.5 because the database file is too large to be downloaded, it is not convenient. If you are interested, just get a table and OK, add the database connection configuration in webconfig
6. download
test demo download http://xiazai.jb51.net/200810/yuanma/TestDataBindControlls.rar [corrected]
7. afterwards,
I have said everything I should say. I hope it will be helpful to everyone. In addition, this test demo has not been added to the cache. If you are interested, you can add it. You are welcome to discuss it, criticism, guidance...