Careful Data Set chaos

Source: Internet
Author: User

I helped my school prepare one thing recently. I got one thing in about two days and turned it over today, but I always felt a little worried. I suddenly wanted to test the data. I wanted to test it and select the data using the binary method. However, I don't know how to get the last record and first record. So I want to test the test slowly, how can we get the last and first record, but the actual test was a big blow. The ASP dataset may be messy.

In the past, when I wrote ASP to read data, I always used "select * from table" to directly select data, and then used

If not Rs. EOF then

Rs. movelast

Do while not Rs. bof then

Response. Write RS ("ID")

.....

Loop

End if

Simply put, we use a loop to directly read all the data in the database. However, if there are tens of thousands of data records, the speed can be imagined. Therefore, we want to use the binary method to select and display the data, but I don't know how to get the starting and final data. I thought of RS again. bof? Rs. the EOF was originally intended to obtain the maximum and minimum values of the field ID, and then compare them. However, in practice, we found that if you use the following things, the maximum and minimum values may not be obtained:

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 while not Rs. bof
Response. Write "ID is" & RS ("ID ")&""
Rs. moveprevious
Loop

Response. Write "first ID =" & frsid &""
Response. Write "last Id =" & lstid &""

The displayed frsid is 6 and lstid is 15. However, the ID of one of the data displayed is 16, that is, the largest ID! = Lstid:

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
First id = 6
Last id = 16
Replace the SQL statement with select * from login order by ID DESC ",:

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
First id = 16
Last id = 6

In this way, the arrangement of the two data is completely different from what is required in SQL (DESC is the case when ASC is re-displayed, and the reality of DESC is indeed ASC ), in addition, the data displayed is completely different from that in the login table.

Conclusion: Data arrangement is completely controlled by both SQL and recordset. When you do not operate pointer records, pointer records are messy. It is best to sort the data in order to facilitate subsequent operations.

?

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.