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
%>
Use string connection code in DW:
"Driver={Microsoft Access Driver (*.mdb)};DBQ=absolute path of the database."
After finishing, open the database server and change
"Driver={Microsoft Access Driver (* .mdb)};DBQ=the absolute path of the database"
to
"Provider=Microsoft.Jet.OLEDB.4.0;data source="& server.mappath("the database path under the server root directory")
and modify the local server to test server
2. Load other pages.
<!--#include file = "Path and name of the page"-->
3. Display the data in the database.
<%=rs("field")%>
4. Output.
Response.Write("text or string");
5. Open the database and create a data set 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 data set
sql="SELECT * FROM data" 'Change your database table name
rs.Open sql,conn,1,1
6. Get the system time.
<%=now()%>
7. Obtain the accessed IP.
<%=request.serverVariables("remote_host")%>
8. Random number.
<%randomize%>
<%=(int(rnd()*n)+1)%>
N is a changeable number
9, jump page.
Response.Redirect("page")
10. A message box pops up.
Response.Write("<script>alert('Message box!')</script>")
11. Use hidden type to pass variables.
< % form method="post" action="mynextpage.asp" >
< % for each item in request.form % >
< input name="< %=item% >" type="HIDDEN"
value="< %=server.HTMLEncode(Request.form(item)) % >" >
< % next % >
</ /form >
12. Organize commonly used SQL statements.
(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 10 * 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 record:
sql="update data table set field name = field value where conditional expression"
sql="update data table set field 1=value 1, field 2=value 2...field n=value n where conditional expression"
(3) Delete data records:
sql="delete from data table where Conditional expression "
sql="delete from data table" (delete all records in the data table)
(4) Add data records:
sql="insert into data table (field 1, field 2, field 3...) values (value 1, Value 2, value 3...)"
sql="insert into target data table select * from source data table" (add records from the source data table to the target data table)
(5) Data record statistical function:
AVG (field name) obtained Generate a table column average
COUNT(*|field name) counts the number of data rows or counts the number of data rows with a value in a certain column
MAX (field name) gets the maximum value of a table column
MIN (field name) gets the minimum value of a table column
SUM(Field Name) Add the values of the data column and
refer to the above function method:
sql="select sum(Field Name) as alias from data table where conditional expression"
set rs=conn.excute(sql)
uses rs("alias") to obtain statistical values, and other functions use the same method as above.
(5) Creation and deletion of data tables:
CREATE TABLE data table name (field 1 type 1 (length), field 2 type 2 (length)...)
Example: CREATE TABLE tab01 (name varchar (50), datetime default now ( ))
DROP TABLE data table name (permanently delete a data table)