1. 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
%>
2. ASP and SQL database connection:
<% @ language = vbscript%> <% DIM conn set conn = server.createObject ("adoDb.connection") con -.open "provider = SQLOLDB; 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
3. SQL common command usage method:
(1) Data Record Screening:
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"
(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"
(3) Delete data records:
SQL = "Delete from Data Sheet WHERE Condition Expression"
SQL = "delete from data table" (deleted all records of data tables)
(4) Add a data record:
SQL = "INSERT INTO Data Sheet (Field 1, Field 2, Field 3 ...) VALUES (value 1, value 2, value 3 ...)
SQL = "INSERT INTO Target Data Table Select * From Source Data Sheet" (Add record of the source data table to the target data sheet)
(5) Data logging statistics:
AVG (Field Name) gives a table bar average count (* | field name) Statistics on the number of data lines or the maximum value of the value of the value of a value for a column. MIN (Field Name) gets the smallest value of a table bar 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.
(5) 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 Datasheet Name (permanently delete a data sheet)
4. Record the method of the set object:
Rs.MoveNext moves the record pointer down the current position down RS.MOVEPREVIOS to move the logger from the current location to the top RS.MoveFirst Move the record pointer to the data table RS.MOVELAST Move the record pointer to the data table The last row RS.absolutePosition = n Moves the record pointer to the data table nth line rs.absolutepage = n Move the record pointer to the first line of the first line of the nth page RS.Pagesize = n Sets each page for n-record RS.PageCount PageSize's Settings Returns the total number rs.RecordCount Returns the total number RS.BOF Returns the record pointer beyond the data table header, the true said whether false is rs.eof returns a record pointer over the end of the data table, true, true Has Rs.Delete deletes the current record, but the record pointer does not move the rs.addnew to add the record to the data table end RS.UPDATE Update Data Table Record
---------------------------------------
RECORDSET object method
Open method
Recordset.open Source, ActiveConnection, Cursortype, LockType, Options
Source RecordSet objects can connect the Command object with the Source property. The Source parameter can be a COMMAND object name, a SQL command, a specified data table name or a Stored ProCedure. If this parameter is omitted, the system uses the Source property of the Recordset object.
ActiveConnection RecordSet objects can connect the Connection object through the ActiveConnection property. The ActiveConnection here can be a connection object or a string parameter containing database configuration (Connectionstring).
CURSORTYPE RECORDSET Object Open method The CURSORTYPE parameter represents what kind of cursor type starts data, including AdopenForwardOnly, AdoPENDYNAMIC, and AdoPenStatic, is described below: ---------------------------------------------------------------------------------------------------------------------- ------------------------------------------- constant constant value description - -------------------------------------------------- --------- AdopenForwardonly 0 default, start a cacope that can only move forward. AdopenKeyset 1 Start a KEYSET type cursor. AdoPendynamic 2 launches a dynamic type cursor. AdoPenStatic 3 launches a cursor for a Static type. -------------------------------------------------- ----------- The above cursor type will directly affect all the properties and methods all of the Recordset object, the following list describes the differences between them.
-------------------------------------------------- ----------- RECORDSET Property AdopenForwardonly AdopenKeyset AdoPENDYNAMIC ADOPENSTATIC --------------------------------- ---------------------------- AbsolutePage does not support you do not support readable write readable write absolutePosition does not support readable write ActiveConnection readable and writable readable write readable write-readable and write-only bookmark does not support you read / write Cachesize readable and write Cachesize Ready-write read-read-read-read-read-read-read-read-read-read-read-read-only read-read-read-read-read-read-read-read-read-read-read-only-read-read-only-read-read-read-like read-read-only-read-read-only-read-read-only-read-read-only-read-read-only-read-read-only-minded write LockType can read and write can read and write can read and write can read and write can read and write MarshalOptions can read and write can read and write can read and write can read and write MaxRecords can read and write can read and write can read and write can read and write PageCount only not supported not supported read-only read PageSize can read and write can read and write can read and write can read and write RecordCount not supported not supported read only read-only Source can read and write can read and write can read and write can read and write State read-only read-only read-only read-only read-only read-only Status Read-only AddNew support support support support CancelBatch support support support CancelupDate support support support CLONE does not support unsupported support support support support support support support support support support GETROWS support support support MOVE does not support support support MOVEFIRST support support support MoveLAST does not support support support MOVENEXT support support support MOVEPREVIOUS does not support support support NEXTRECORDSET Support Support Open Support Support Support REQUERY Support Support Support Supporting RESYNC does not support support support support support Support support support support UPDATE support support support support UPDATEBATCH Support support support -------------------------- ---------------------------------- in which the nextRecordset method does not apply to the Microsoft Access database. The LockType parameter of the LockType RecordSet object Open method indicates the Lock type to be used. If this parameter is ignored, the system will be preset with the LockType property of the Recordset object. The LockType parameter contains AdlockReadOnly, AdlockPrsSIMistic, AdlockOptimistic, and AdlockbatchOptimistic, etc., which are described below: