Simple tutorial on typical ASP database operations

Source: Internet
Author: User

<%

1
Set cn = server. createobject ("adodb. connection ")

Object cn used to create a database connection


2
Cn. open "... con_str ..."

Call the open method of cn and use the string in the middle of double quotation marks as a parameter to open the database (you need to open the database before the operation is complete, and then you need to close it to call the close method of cn ). You can also choose to use the system or user data source, but it is not recommended because many times you do not have operation permissions on the virtual host, so use the connection string.


3
Set rs = server. createobject ("adodb. recordset ")

Rs used to create a data record

 

4
Strsql = "select * from product where product_name =" & request ("name ")&""

Write SQL statements for specific functions and assign them to the variable strsql


5
Set rsw.cn.exe cute (strsql)

Use strsql as the parameter to call the execute method of cn to connect the database of cn to execute the SQL statement stored in the variable strsql, and assign the query results (all Qualified Data Records) obtained after the statement is executed to the record set object rs. Of course there are many other methods, use it after you are familiar with other methods of other objects.

 

The database does not have any matching records.


6
Do until rs. eof
Response. write rs ("product_name ")
Rs. movenext
Loop

The data in the dataset is stored in the format of rs. bof --- data record 1 --- data record 2 --- data record 3 ...... Data Record n --- rs. eof; display the product_name field values in all rs record sets one by one using a loop statement


7
Rs. colse

Disable record set and release memory

Cn. close

Close the connection and release the memory. These are the key points. Otherwise, the server consumption will increase.


%>

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.