Rs.Open sql,conn,1,1 and Rs.Open sql,conn,1.3 and Rs.Open sql,conn,3,2 different application techniques

Source: Internet
Author: User
Often develop ASP but for the meticulous statement, the truth is not very clear, here a simple introduction.
Under normal circumstances
Read the data with Rs.Open sql,conn,1,1
Modifying data: Rs.Open sql,conn,1,3
Delete data: Directly to Conn.execute ("Delete * from new where id=1").

The Rs.Open syntax is as follows: Rs. Open Source,activeconnection,cursortype,locktype

Source is a SQL statement, ActiveConnection is a database connection, CursorType is a cursor, and LockType is a data lock type.

CursorType

Constants Description
adOpenForwardOnly (value 0) (the default) opens a forward-only type cursor.
adOpenKeyset (value 1) Opens the keyset type cursor.
adOpenDynamic (value 2) opens a dynamic type cursor.
adOpenStatic (value 3) opens a static type cursor.


LockType


Constants Description
adLockReadOnly (value 1) (default) read-only-cannot change data.
adLockPessimistic (value 2) pessimistic locking (one by one)-the provider completes the work necessary to ensure that records are successfully edited, typically by locking the record of the data source as soon as it is edited.
adLockOptimistic (value 3) Open lock (one by one)-the provider uses optimistic locking, which locks records only when the Update method is invoked.
adLockBatchOptimistic (value 4) Open batch update-for batch update mode (as opposed to immediate update mode).

CursorType
0 forward-only cursors, can only navigate forward records, do not support paging, Recordset, BookMark
A 1-keyset cursor, the changes that other users make to the record will be reflected in the recordset, but other users adding or deleting records will not be reflected in the recordset. Support paging, Recordset, BookMark
2 Dynamic cursors are the most powerful, but also the most expensive sources. User changes to the record, add or delete records will be reflected in the recordset. Support full feature browsing.
3 static cursors, just a snapshot of the data, user changes to the record said, add or delete records are not reflected in the recordset. Supports moving forward or backward

LockType
The LockType is the lock type of the recordset, and the value is:
1 lock type, default, read only, can't make any changes
2 The safest way to lock records as soon as they are edited
3 The Recordset is locked only when the Update method is called, and other previous operations can still make changes, inserts, and deletes to the current record.
4 when editing records are not locked, but change, insert and delete
Rs.Open sql,conn,3,2
These two are cursors, and the specific effect is:
Rs. OPEN sql,conn,a,b
A:
adOpenForwardOnly (=0)
Read-only and the current data record can only move Down
adOpenKeyset (=1)
Read-only, the current data record is free to move
adOpenDynamic (=2)
Can read and write, the current data record is free to move
adOpenStatic (=3)
Can read and write, the current data record can move freely, can see the new record
B:
adLockReadOnly (=1)
Default lock type, Recordset is read-only, record cannot be modified
adLockPessimistic (=2)
Pessimistic locking, when a record is modified, the data provider attempts to lock the record to ensure that it is successfully edited. Lock the record immediately as soon as the editor starts.
adLockOptimistic (=3)
Optimistic locking is not locked until the update record is submitted with the Update method.
adLockBatchOptimistic (=4)
Bulk optimistic locking allows multiple records to be modified, and records are locked only after the UpdateBatch method is invoked.
When you do not need to change any records, you should use a read-only recordset so that the provider does not have to do any testing.
For general use, optimistic locking may be the best option because records are locked for a short period of time,
The data is updated during this time period. This reduces the use of resources.
To sum up:
The sql,conn,1,1 representative does not allow updates, and is generally used for query operations.
sql,conn,1,3 delegates allow updates, typically for inserts, updates, and deletions.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.