ASP and ACCESS database

Source: Internet
Author: User
1. You can customize a table to call up data from the database:
<% Set rs = server. CreateObject ("adodb. recordset ")
Rs. Open "select * from ad order by bs", conn, 1, 1
Do while not rs. EOF
Response. write "<a href =" & trim (rs ("url") & "target = _ blank>" & trim (rs ("wordlink ")) & "</a> <br>"
Rs. MoveNext
Loop
Rs. Close
Set rs = nothing
%>
Note: "wordlink" is a field name in the table.
2. This statement is generally used to connect to a database:
<! -- # Include file = "conn. asp" -->
The Conn. asp code is as follows:
<% @ CODEPAGE = "936" %> // you can skip this sentence.
<%
Dim conn
Dim connstr
Dim db
Db = "db/my. mdb"
Set conn = Server. CreateObject ("ADODB. Connection ")
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath (db)
Conn. Open connstr
Startime = timer ()
%>
3. For example, the following is the page for adding a message: (the name of the message is tianjia. asp)
<! -- # Include file = "conn. asp" -->
<%
Set rs = server. createobject ("adodb. recordset ")
Name = Request ("name ")
Mail = Request ("email ")
Face = Request ("face ")
SQL = "select * from message" (message is the table name)
Rs. open SQL, conn, 3, 3
Rs. addnew
Rs ("A_Name") = name
Rs ("A_Mail") = mail
Rs ("face") = face // This is the selected image. You can use image/1.jpg in the fields of the database table.
Rs. update
Rs. close
Response. Redirect "xianshi. asp" // This sentence is a redirection page, that is, jump to xianshi. asp
%>
<%
Set rs = nothing
Conn. close
Set conn = nothing
%>
On the message writing page, add the following statement: <FORM action = tianjia. asp method = post> to call tianjia. asp when submitting the message.

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.