Implementation of random extraction database record routines by ASP

Source: Internet
Author: User
Tags chr end sql
Data | database | random <%
"An example of a random reading of a record from a database
Set Rs1=server. CreateObject ("Adodb.recordset")
Set Rs=server. CreateObject ("ADODB.") RECORDSET ")
Sql= "Select ID from Article ORDER by id DESC"
Rs. Open sql,dataconn,3,3
If not Rs. EOF Then
TOTAL=RS ("id") takes the largest ID
Rs. Close
Randomize
R=int ((total-1+ 1) * Rnd + 1)
Sql= "Select id,content from Article where id=" & R
Rs. Open sql,dataconn,3,3
If not Rs. EOF Then
Content=rs ("content")
Content=replace (CONTENT,CHR), "<br>"
Content=replace (CONTENT,CHR), "<br>"
Content=replace (Content, "<br><br>", "<br>")
Response.Write Content
Else
sql1= "Select content from Article"
Rs1. Open sql1,dataconn,3,3
If not EOF then
"Take the first record as the default display record
Content=rs1 ("content")
Content=replace (CONTENT,CHR), "<br>"
Content=replace (CONTENT,CHR), "<br>"
Content=replace (Content, "<br><br>", "<br>")
Response.Write Content
Else
The database is empty
Response.Write "does not exist"
End If
Rs1. Close
End If
Rs.close
End If
Set rs=nothing
%>

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.