Very useful learning ASP commonly used code page 1/2

Source: Internet
Author: User

1. database connection.
ASP and Access database connection:

<% @ Language = VBscript %>
<%
Dim conn, mdbfile
Mdbfile = server. mappath ("database name. mdb ")
Set conn = server. createobject ("adodb. connection ")
Conn. open "driver = {microsoft access driver (*. mdb)}; uid = admin; pwd = Database Password; dbq =" & mdbfile

%>

ASP and SQL database connection:

<% @ Language = VBscript %>
<%
Dim conn
Set conn = server. createobject ("ADODB. connection ")
Con. open "PROVIDER = SQLOLEDB; data source = SQL server name or IP address; UID = sa; PWD = DATABASE Password; DATABASE = DATABASE Name
%>

Connection code using strings in DW:

"Driver = {Microsoft Access Driver (*. mdb)}; DBQ = absolute path of the Database"

Open the database server

"Driver = {Microsoft Access Driver (*. mdb)}; DBQ = absolute path of the Database"

Change

"Provider = Microsoft. Jet. OLEDB.4.0; data source =" & server. mappath ("database path under the server root directory ")

Modify the local server to a test server.

2. Load other pages.

<! -- # Include file = "Page path and name" -->

3. display data in the database.

<% = Rs ("field") %>

4. output.

Response. Write ("text or string ");

5. Open the database and create a DataSet object.

Set conn = server. CreateObject ("ADODB. connection ")
Conn. open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & server. MapPath ("***/photodata. mdb") 'change your database file storage path
Set rs = server. createobject ("ADODB. recordset") 'create a dataset
SQL = "SELECT * FROM data" 'change the name of your database table
Rs. Open SQL, conn, 1, 1

6. Obtain the system time.

<% = Now () %>

7. Obtain the IP address to access.

<% = Request. serverVariables ("remote_host") %>

8. Random Number.

<% Randomize %>
<% = (Int (rnd () * n) + 1) %>
N is a changeable variable.

9. Jump to the page.

Response. Redirect ("page ")

10. The message box is displayed.

Response. Write ("<script> alert ('message box! ') </Script> ")

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.