Simple ASP database operation tutorial

Source: Internet
Author: User
Simple ASP database operation tutorial
<1>. Database connection (used to separate the connection file conn. asp)
<%
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open "DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ =" & Server. MapPath ("bsdb1user. mdb ")
%>
(Used to connect the user. mdb Database in the bbsdb1 directory)
<2> Display database records
Principle: displays the records in the database one by one in the client browser, reads each record in the database in sequence
If it is from start to end: use a loop and determine whether the pointer is used until the end: not rs. eof
If it is from the end to the header: use a loop and determine whether the pointer is used to start using: not rs. bof
<! -- # Include file = conn. asp --> (conn. asp is used to open user. mdb data in the bbsdb1 directory.
Library)
<%
Set rs = server. CreateObject ("adodb. recordset") (create a recordset object)
Sqlstr = "select * from message" ----> (message is a data table in the database, that is,
The data table that stores the data)
Rs. open sqlstr, conn, 1, 3 ----> (indicates how to open the database)
Rs. movefirst ----> (move the pointer to the first record)
While not rs. eof ----> (judge whether the pointer ends)
Response. write (rs ("name") ----> (display the name field in the message Table)
Rs. movenext ----> (move the pointer to the next record)
Wend ----> (loop end)
------------------------------------------------------
Rs. close
Conn. close is used to close the database.
Set rs = nothing
Set conn = nothing
-------------------------------------------------------
%>
The response object is the information sent by the server to the client browser.
<3> add database records
Rs. addnew and rs. update functions are used to add database records.

<! -- # Include file = conn. asp --> (conn. asp is used to open user. mdb data in the bbsdb1 directory.
Library)
<%
Set rs = server. CreateObject ("adodb. recordset") (create a recordset object)
Sqlstr = "select * from message" ----> (message is a data table in the database, that is,
The data table that stores the data)
Rs. open sqlstr, conn, 1, 3 ----> (indicates how to open the database)

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.