|
The type of cursor used in a Recordset object.
Sets or returns one of the following CursorTypeEnum values:
Constant |
Description |
adOpenForwardOnly |
Forward-only cursor. Default. Identical to a static cursor except that you can only scroll forward through records. This improves performance in situations when you only need to make a single pass through a recordset. |
adOpenKeyset |
Keyset cursor. Like a dynamic cursor, except that you can't see records that other users add, although records that other users delete are inaccessible from your recordset. Data changes by other users are still visible. |
adOpenDynamic |
Dynamic cursor. Additions, changes, and deletions by other users are visible, and all types of movement through the recordset are allowed, except for bookmarks if the provider doesn't support them. |
adOpenStatic |
Static cursor. A static copy of a set of records that you can use to find data or generate reports. Additions, changes, or deletions by other users are not visible. |
Use the CursorType property to specify the type of cursor that should be used when opening the Recordset object. The CursorType property is read/write when the recordset is closed and read-only when it is open.
If a provider does not support the requested cursor type, the provider may return another cursor type. The CursorType property will change to match the actual cursor type in use when the recordset object is open. To verify specific functionality of the returned cursor, use the ADO Recordset Object Supports Method. After you close the recordset, the CursorType property reverts to its original setting.
The following chart shows the provider functionality (identified by Supports method constants) required for each cursor type.
CursorType |
The Supports method must return True for these constants |
adOpenForwardOnly |
none |
adOpenKeyset |
adBookmark, adHoldRecords, adMovePrevious, adResync |
adOpenDynamic |
adMovePrevious |
adOpenStatic |
adBookmark, adHoldRecords, adMovePrevious, adResync |
Note
Although Supports(adUpdateBatch) may be true for dynamic and forward-only cursors, for batch updates you should use either a keyset or static cursor. Set the ADO Recordset Object LockType Property to adLockBatchOptimistic, and set the CursorLocation property to adUseClient (or its synonym, adUseClientBatch) to enable the Microsoft Client Cursor Engine, which is required for batch updates.
This Visual Basic example demonstrates setting the CursorType and LockType properties before opening a recordset. It also shows the value of the ADO Recordset Object EditMode Property under various conditions. The EditModeOutput function is required for this procedure to run.
Public Sub EditModeX()
Dim cnn1 As ADODB.Connection
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
` Open recordset with data from Employee table.
Set cnn1 = New ADODB.Connection
strCnn = "driver={SQL Server};server=srv;" & _
"uid=sa;pwd=;database=pubs"
cnn1.Open strCnn
Set rstEmployees = New ADODB.Recordset
Set rstEmployees.ActiveConnection = cnn1
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockBatchOptimistic
rstEmployees.Open "employee", , , , adCmdTable
` Show the EditMode property under different editing
` states.
rstEmployees.AddNew
rstEmployees!emp_id = "T-T55555M"
rstEmployees!fname = "temp_fname"
rstEmployees!lname = "temp_lname"
EditModeOutput "After AddNew:", rstEmployees.EditMode
rstEmployees.UpdateBatch
EditModeOutput "After UpdateBatch:", rstEmployees.EditMode
rstEmployees!fname = "test"
EditModeOutput "After Edit:", rstEmployees.EditMode
rstEmployees.Close
` Delete new record because this is a demonstration.
cnn1.Execute "DELETE FROM employee WHERE emp_id = 'T-T55555M'"
End Sub
Public Function EditModeOutput(strTemp As String, _
intEditMode As Integer)
` Print report based on the value of the EditMode
` property.
Debug.Print strTemp
Debug.Print " EditMode = ";
Select Case intEditMode
Case adEditNone
Debug.Print "adEditNone"
Case adEditInProgress
Debug.Print "adEditInProgress"
Case adEditAdd
Debug.Print "adEditAdd"
End Select
End Function
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.