The syntax of Rs.Open is as follows: rs.Open Source, ActiveConnection, CursorType, LockType Source is the sql statement, ActiveConnection is the database connection, CursorType is the cursor, and LockType is the data lock type.
I often develop asp but I am not sure about the details. Here is a brief introduction.
Normally
To read data, use rs.open sql,conn,1,1
Modify data: rs.open sql,conn,1,3
Delete data: directly use conn.execute("delete * from new where id=1").
The syntax of Rs.Open is as follows: rs.Open Source,ActiveConnection,CursorType,LockType
Source is the sql statement, ActiveConnection is the database connection, CursorType is the cursor, and LockType is the data lock type.
CursorType
Constant description
adOpenForwardOnly(value 0) (default value) opens a forward-only cursor.
adOpenKeyset (value 1) opens a keyset type cursor.
adOpenDynamic (value 2) opens a dynamic type cursor.
adOpenStatic (value 3) opens a static type cursor.
LockType
Constant description
adLockReadOnly (value 1) (default) Read-only - data cannot be changed.
adLockPessimistic (value 2) Conservative locking (one-by-one) — The provider does the work required to ensure successful editing of records, typically by locking the data source's records immediately upon editing.
adLockOptimistic (value 3) Open locking (one by one) - The provider uses open locking and only locks records when the Update method is called.
adLockBatchOptimistic (value 4) Open batch update - used in batch update mode (as opposed to immediate update mode).
CursorType
0 Only forward cursor, can only browse records forward, does not support paging, Recordset, BookMark
1 key set cursor, modifications made by other users to records will be reflected in the records set, but records added or deleted by other users will not be reflected in the records set. Support paging, Recordset, BookMark
2 Dynamic cursors have the most powerful functions, but also consume the most resources. Modifications made by users to records, adding or deleting records will be reflected in the record set. Supports full-featured browsing.
3. A static cursor is just a snapshot of the data. Modifications made by the user to records, adding or deleting records will not be reflected in the record set. Supports moving forward or backward
LockType
LockType is the lock type of the recordset, and its value is:
1 Lock type, default, read-only, no modifications can be made
2 Lock records immediately when editing, the safest way
3 The recordset is locked only when the Update method is called, and other previous operations can still change, insert, and delete the current record.
4 Records are not locked when editing, and changes, insertions, and deletions
rs.open sql,conn,3,2
These two are cursors, their specific functions are:
RS.OPEN SQL,CONN,A,B
A:
ADOPENFORWARDONLY(=0)
Read-only, and the current data record can only be moved downwards
ADOPENKEYSET(=1)
Read-only, the current data record can be moved freely
ADOPENDYNAMIC(=2)
Readable and writable, the current data record can be moved freely
ADOPENSTATIC(=3)
Readable and writable, current data records can be moved freely, new records can be seen
B:
ADLOCKREADONLY(=1)
The default lock type is that the recordset is read-only and records cannot be modified.
ADLOCKPESSIMISTIC(=2)
Pessimistic locking, when a record is modified, the data provider will try to lock the record to ensure that the record is successfully edited. As soon as editing begins, the record is locked.
ADLOCKOPTIMISTIC(=3)
Optimistic locking does not lock the record until the updated record is submitted using the Update method.
ADLOCKBATCHOPTIMISTIC(=4)
Batch optimistic locking allows multiple records to be modified, and the records are locked only after the UpdateBatch method is called.
When no records need to be modified, a read-only recordset should be used so that the provider does not need to do any detection.
For general use, optimistic locking is probably the best option, since records are only locked for a short period of time,
The data is updated during this time. This reduces resource usage.
To summarize:
sql,conn,1,1 means no updates are allowed and is generally used for query operations.
sql,conn,1,3 means updates are allowed and is generally used for insert, update and delete operations.