Reference | object | recordset | detailed | Statement 1. ASP to connect to an Access database:
2. asp and SQL database connection:
Set Recordset object: Set Rs=server.createobject ("Adodb.recordset")
Rs.Open SQL statement, conn,3,2
3. SQL Common Command use method:
(1) Data record filtering: sql= "SELECT * from data table where field name = field value order BY field name [desc]" sql= "SELECT * from datasheet 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 datasheet where field name in (' Value 1 ', ' Value 2 ', ' Value 3 "Sql=" select * from datasheet 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 datasheet 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 datasheet" (delete all records from datasheet)
(4) Add data record: sql= "INSERT into datasheet (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 logging statistics function: AVG (field name) to get 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 to the method that references the above function:
Sql= "Select sum (field name) as Alias from data table where condition expression"
Set Rs=conn.excute (SQL) uses RS ("Alias") to obtain the value of the EC, and other functions are used as above. (5) Data table creation and deletion: 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 delete a data table) 4. Method of Recordset object: Rs.movenext moves the record pointer down one row from the current position
Rs.moveprevious move the record pointer up one row from the current position
Rs.movefirst move the record pointer to the first row of the datasheet
Rs.movelast move the record pointer to the last row of the datasheet
Rs.absoluteposition=n move the record pointer to the nth row of the datasheet
Rs.absolutepage=n move the record pointer to the first row of page N
Rs.pagesize=n set every page to N records
Rs.pagecount returns the total number of pages based on pagesize settings
Rs.recordcount returns the total number of records
RS.BOF returns whether the record pointer is over the first end of the datasheet, True indicates Yes, FALSE is no
Rs.eof returns whether the record pointer is over the end of the datasheet, True indicates Yes, FALSE is no
Rs.delete deletes the current record, but the record pointer does not move down
Recordset Object method Open method Recordset.Open Source,activeconnection,cursortype,locktype,optionssource
The Recordset object can connect to the command object through the Source property. The source parameter can be a command object name, a section of SQL command, a specified data table name, or a stored Procedure. If this argument is omitted, the system takes the source property of the Recordset object. ActiveConnection
The Recordset object can connect connection objects by ActiveConnection properties. The ActiveConnection can be a connection object or a string parameter containing the database connection information (ConnectionString). CursorType
The CursorType parameter of the Recordset object Open method indicates what cursor type will start the data, including adOpenForwardOnly, adOpenKeyset, adOpenDynamic, and adOpenStatic. It is described as follows:
These cursor types will directly affect all properties and methods of the Recordset object, and the following list illustrates the differences between them. -------------------------------------------------------------
Where the NextRecordset method does not apply to Microsoft Access databases. LockType
The LockType parameter of the Recordset object's Open method represents the lock type to take, and if this argument is omitted, then the system takes the LockType property of the Recordset object as the preset value. LockType parameters include adLockReadOnly, adlockprssimistic, adLockOptimistic, and adLockBatchOptimistic, Described below:-------------------------------------------------------------
adLockReadOnly 1 defaults, the Recordset object starts as read-only and cannot run AddNew, Update, and Delete methods
Adlockprssimistic 2 When the data source is being updated, the system temporarily locks the actions of other users to maintain data consistency.
adLockOptimistic 3 When the data source is being updated, the system does not lock other users ' actions, other users can add, delete, and change the operation of the data.
adLockBatchOptimistic 4 When the data source is being updated, other users must change the CursorLocation property to Adudeclientbatch to add, delete, and modify the data.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.