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> ")
11, use the hidden type to pass the variable.
<% form method= "POST" action= "mynextpage.asp" >
<% for per item in request.form% >
< input namee= "<%=item% >" type= "HIDDEN"
Value= "<%=server. HTMLEncode (Request.Form (item)% > ">
<% next% >
</form >
12, common SQL statement collation.
(1) Data record filtering:
Sql= "SELECT * from data table where field name = field value order BY field name [desc]"
Sql= "SELECT * from data table where field name like '% field value% ' Order by field name [desc]"
Sql= "SELECT top * from data table where field name order by field name [desc]"
Sql= "SELECT * from data table where field name in (' Value 1 ', ' Value 2 ', ' Value 3 ')"
Sql= "SELECT * from data table where field name between value 1 and value 2"
(2) Update data records:
sql= "Update data table set field name = field value where Condition expression"
Sql= Update data Table set field 1= value 1, field 2= value 2 ... field n= value n Where Condition expression "
(3) Delete data records:
Sql= "Delete from data table where condition expression"
Sql= "Delete from data table" (delete all records from datasheet)
(4) Adding data records:
sql= INSERT into Data table (field 1, Field 2, Field 3 ...) VALUES (value 1, value 2, value 3 ...)
Sql= INSERT INTO Target datasheet SELECT * from source datasheet (add a record from the source datasheet to the destination datasheet)
(5) Data record statistic function:
AVG (field name) to derive a table column average
Count (*| field name) statistics on the number of data rows or the number of data rows that have a value for a column
Max (field name) gets the maximum value of a table column
Min (field name) gets the smallest value of a table column
sum (field name) adds the value of the data bar
How to reference the above function:
Sql= "Select sum (field name) as Alias from data table where condition expression"
Set Rs=conn.excute (SQL)
Using RS ("Alias") to obtain the value of the unified, other functions using the same.
(5) The establishment and deletion of the data table:
CREATE Table datasheet Name (field 1 type 1 (length), Field 2 type 2 (length) ...)
Example: CREATE TABLE tab01 (name varchar, datetime default Now ())
drop table datasheet name (permanently deletes a data table)