Watch out for data sets.

Source: Internet
Author: User
Tags final
Data recently helped the school to do a thing, about two days to get one, and today turned over, but always feel a little worried. Suddenly want to test the test, would like to test the data by using a binary selection, but do not know how to get the last record and the first, so I want to slowly test the test, how to get the last and the first, But the actual test was a big shock. The possibility of a messy ASP dataset.

Previously, when writing ASP to read data, always use "SELECT * from table" To select data directly, and then use the

If not rs.eof Then

Rs.movelast

Do as not Rs.bof Then

Response.Write Rs ("ID")

.....

Loop

End If

Simple is to use a loop to read all the data directly from the database, but if the data has tens of thousands of, the speed is conceivable, so want to use the binary method to select the data to display, but do not know how to get the start and the final data, and thought of the Rs.bof rs.eof It was supposed to be how to get the maximum value of the field ID, the minimum value, and then compare it, but the actual operation found that if you use the following things, you do not necessarily get the maximum and minimum values:

If not Rs.bof Then
Rs.movefirst
Frsid=rs ("ID")
End If
If not rs.eof Then
Rs.movelast
Lstid=rs ("ID")
End If
Do as not Rs.bof
Response. Write "ID is" &RS ("id") & "
"
Rs. MovePrevious
Loop

Response. Write "Id= &frsID&"
"
Response.Write "Last Id=" &lstID& "
"


The frsid=6,lstid=15 displayed, but there is a data ID of 16 in the total data displayed, which means that the largest id! =lstid (I always thought this was a want to wait), the final check found that there is a problem with the SQL statement, changed to "Select * from Login ORDER by ID ASC" when the display:

ID is 16
ID is 15
ID is 14
ID is 13
ID is 12
ID is 11
ID is 10
ID is 8
ID is 7
ID is 6
The id=6
Last id=16
When you change SQL to select * from Login-ID Desc, it is:

ID is 6
ID is 7
ID is 8
ID is 10
ID is 11
ID is 12
ID is 13
ID is 14
ID is 15
ID is 16
The id=16
Last id=6

Such two data are arranged completely different from those required in SQL (which was DESC when the ASC was shown, to the actual ASC of the DESC), and the display was completely different from the data in the login table.

Conclusion: The arrangement of data is entirely controlled by both SQL and Recordset. When you do not record the operation of the pointer, the pointer record is chaotic, the best data operation, first tidy up the data arrangement, so that it can be arranged in order to facilitate the operation later.





Related Article

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.