Useful for learning ASP commonly used code 1th/2 page _asp Basics

Source: Internet
Author: User
1, database connection.
ASP to connect to an Access database:

<%@ 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 to connect to SQL database:

<%@ 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
%>

The DW uses string concatenation code:

"Driver={microsoft Access Driver (*.mdb)};D bq= Absolute path to the database"

When you are done, open the database server and

"Driver={microsoft Access Driver (*.mdb)};D bq= Absolute path to the database"

Into

"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Database path under Server root directory")

and modify the local server into a test server


2, loading other pages.

<!--#include file = "path and name of page"-->

3, display the data in the database.

<%=rs ("field")%>

4, output.

Response.Write ("literal or string");



5. Open the database and set up the 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") ' establishes a dataset
Sql= "SELECT * from data" To change your database table name
Rs. Open sql,conn,1,1

6, to obtain the system time.

<%=now ()%>

7, to obtain access to the IP.

<%=request.servervariables ("Remote_host")%>

8, random number.

<%randomize%>
<%= (int (rnd () *n) +1)%>
N is a number that can be changed

9, jump page.

Response.Redirect ("page")

10, pop-up message box.

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

Current 1/2 page 12 Next read the full text

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.