Collected web programming development common code

xiaoxiao2021-03-06  17

1. ASP and Access database connection:

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

2. ASP and SQL database connection:

DIM Conn

Set conn = server.createObject ("adoDb.connection")

Con. PROVIDER = SQLOLEDB; DATA SOURCE = SQL server name or IP address; UID = SA; PWD = database password; Database = database name

Establish record set objects:

SET RS = Server.createObject ("AdoDb.Recordset")

RS.Open SQL statement, conn, 3, 2

SQL common command usage:

Data Record Filter:

SQL = "SELECT * FROM DATA WHERE Field Name = Field Value ORDER BY Field Name"

SQL = "SELECT * FROM DATA WHERE Field Name Like '% Field Value%' ORDER BY Field Name"

SQL = "SELECT TOP 10 * From Datasheet WHERE Field Name Order By Field Name"

SQL = "SELECT * FROM DATA WHERE Field Name in ('value 1', 'value 2', 'value 3')"

SQL = "SELECT * FROM DATA WHERE Field Name BetWeen Value 1 AND Value 2" update data record:

SQL = "Update Datasheet 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 Conditions Expression"

Delete data records:

SQL = "Delete from Data Sheet WHERE Condition Expression"

SQL = "delete from data table" (deleted all records of data tables)

Add a data record:

SQL = "INSERT INTO Data Sheet (Field 1, Field 2, Field 3 ...) Valuess (value 1, value 2, value 3 ...)"

SQL = "INSERT INTO Target Data Table Select * From Source Data Sheet" (Add a record of the source data table to the target data table) Data logging statistics:

AVG (field name) draws a table column average

Count (* | field name) Statistics on the number of data lines or the number of data line counts on a certain column

Max (field name) get the largest value of a table bar

MIN (field name) gets the smallest value of a table column

SUM (field name) adds the value of the data bar

Citing the above function:

SQL = "SELECT SUM (Field Name) AS alias from Datasheet Where Condition Expression

SET RS = conn.excute (SQL)

Use RS ("alias") to get the value, and other functions are used.

Establishment and deletion of data sheets:

Create Table Data Sheet Name (Field 1 Type 1 (Length), Field 2 Type 2 (Length) ...)

Example: Create Table Tab01 (Name Varchar (50), DateTime Default Now () DROP TABLE Dataset Name (permanently deleted a data sheet)

Record the method of the set object:

Rs.MoveNext moves the record pointer down from the current position down

Rs.MovePrevious moves the record pointer from the current location

Rs.MoveFirst moves the record pointer to the first line of the data table

Rs.Movelast moves the record pointer to the last line of the data table

Rs.absolutePosition = n Moves the record pointer to the data table N

Rs.absolutePage = N Move the record pointer to the first line of the nth page

rs.pagesize = n Sets each page as N records

Rs.PageCount Returns the number of pages based on PageSize

Rs.Recordcount Returns the total number of records

rs.bof returns the record pointer beyond the head end of the data sheet, True is indicated by the false

rs.eof Returns whether the pointer exceeds the end of the data table, True is indicated by the FALSE

Rs.delete deletes the current record, but the record pointer will not move downward

Rs.addnew Add record to the end of the data

Rs.Update Update Data Table Record

Judging the filled data is a digital type

IF not isnumeric (Request ("Field Name")) Then

Response.write "is not a number"

Else

Response.write "Digital"

END IF page execution time:

<% startime = Timer ()%>

.... ....

content

...

end

<%

DIM endtime

EndTime = Timer ()

Response.write "page execution time: " & formatNumber ((endtime-startime) * 1000, 5) & " millisecond"

%> Defines the size of the start window when opening the web page