1. ASP and Access database connection:
<% @Language = VBScript%> <% DIM conn, mdbfilemdbfile = 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 = 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 table where field name = field value ORDER BY field name [DESC]"
SQL = "SELECT * FROM DATA WHERE Field Name Like '% Field Value' Order By Field Name [DESC]"
SQL = "SELECT TOP 10 * FROM DATA WHERE Field Name ORDER BY Field Name [DESC]"
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 WHERE Condition Expression" SET RS = Conn.excute (SQL) The value of the value is obtained by RS ("alias", and other functions are using the same.
(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
The SourceRecordset object 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.
ActiveConnectionRecordset 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).
CURSORTYPERECORDSET 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 support OPEN support support support support support support support support Support RESYNC does not support support support Supports support support Support support Update support support support support UPDATEBATCH support support support support ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ The nextRecordset method does not apply to the Microsoft Access database.
LockTypeRecordset Object Open method The LockType parameter represents the Lock type to be used, if this parameter is ignored, then the system is preset with the LockType property of the Recordset object. The LockType parameter contains AdlockReadonly, AdlockPrsSIMistic, AdlockOptimistic, and AdlockBatchOptimistic, etc., is described below: ------------------------------------------------------------------------------------------------------------------------------------ -------------------------- constant constant value description ------------------- ------------------------------------------ AdlockReadOnly 1 default value, Recordset Objects are launched in read-only way, and how to operate AddNew, Update, and Delete. AdlockPrsSIMistic 2 when the data source is being updated, the system is temporarily locked to maintain data consistency. AdlockOptimistic 3 When the data source is being updated, the system does not lock the action of other users, and other users can increase, delete, and change the data. AdlockBatchOptimistic 4 When the data source is being updated, other users must change the CURSORLOCATION property to ADUDECLIENTBATCH to increase, delete, and change the data.