Command Execute Method
Connection Execute Method
Connection Object
Recordset Open Method
Recordset Object
EVENT: Connection::WillExecute
WillExecute
Source, CursorType, LockType, Options, adStatus, pCommand, pRecordset, pConnection
The
WillExecute
event can be fired just before a
Command Execute, Connection Execute,
or
Recordset Open
method starts to execute. This event is one of two command execution management events that can be called. The other event is
ExecuteComplete
.
An event is simply a subroutine that can be called automatically after a specific operation has occurred. This subroutine can contain any code that you need to run when the event occurs. The subroutine will only be called if it is included in your code. Future calls to the event subroutine can be cancelled by setting the
adStatus
parameter to be the
adStatusUnwantedEvent
constant (see table below) before the event returns.
There are eight parameters that are passed to this event.
The
Source
parameter is a string that contains either an SQL command or a stored procedure name.
The
CursorType
parameter is a long value that is one of
CursorTypeEnum
constants.
CursorTypeEnum constants
Constant
Value
Description
adOpenDynamic
2
Provides a dynamic cursor
adOpenForwardOnly
0
Default, provides a forward-only cursor
adOpenKeyset
1
Provides a keyset cursor
adOpenStatic
3
Provides a static cursor
adOpenUnpecified
-1
Unspecified
The
LockType
parameter is a long value that is one of
LockTypeEnum
constants.
LockTypeEnum Constants
Constant
Value
Description
adLockBatchOptimistic
4
Multiple users can modify the data and the changes are cached until
BatchUpdate
is called
adLockOptimistic
3
Multiple users can modify the data which is not locked until
Update
is called
adLockPessimistic
2
The provider locks each record before and after you edit, and prevents other users from modifying the data
adLockReadOnly
1
Read-only data
adLockUnspecified
-1
Lock type unknown
The
Options
parameter is a long value that is one or more of the
CommandTypeEnum
or
ExecuteOptionEnum
constants. It comes from the
Options
parameter of the
Command Execute, Connection Execute,
or
Recordset Open
methods.
CommandTypeEnum Constants
Constant
Value
Description
adCmdFile
256
Evaluate as a previously persisted file
adCmdStoredProc
4
Evaluate as a stored procedure
adCmdTable
2
Have the provider generate a SQL query and return all rows from the specified table
adCmdTableDirect
512
Return all rows from the specified table
adCmdText
1
Evaluate as a textual definition
adCmdUnknown
8
The type of the CommandText parameter is unknown
adCmdUnspecified
-1
Default, does not specify how to evaluate
ExecuteOptionEnum Constants
Constant
Value
Description
adAsyncExecute
0x10
Execute asynchronously
adAsyncFetch
0x20
Rows beyond the initial quantity specified should be fetched asynchronously
adAsyncFetchNonBlocking
0x40
Records are fetched asynchronously with no blocking of additional operations
adExecuteNoRecords
0x80
Does not return rows and must be combined with
adCmdText
or
adCmdStoredProc
adOptionUnspecified
-1
The CommandText parameter is unspecified
The
adStatus
parameter defines the status of the event and is set to either the
adStatusOK
or the
adStatusCantDeny
values of the
EventStatusEnum
constants. Before the event returns, to prevent unwanted future firings of this event, set this parameter to
adStatusUnwantedEvent
, or set it to
adStatusCancel
to cancel the operation that fired the event.
EventStatusEnum Constants
Constant
Value
Description
adStatusCancel
4
Cancels the operation that fired the event
adStatusCantDeny
3
Cannot cancel pending operation
adStatusErrorsOccurred
2
Indicates that warnings and/or errors occurred
adStatusOK
1
The operation that fired the event was successful
adStatusUnwantedEvent
5
The operation that generated the event cannot generate future events
The
pCommand
parameter is set either to the
Command
object that was executed or to
Nothing
.
The
pRecordset
parameter is set either to the
Recordset
object that resulted from the execution of the command or to
Nothing
.
The
pConnection
parameter is the
Connection
object that is associated with the execution.
Code (Visual Basic):
' Use the WithEvents keyword to designate that events
' can be handled by this Connection object
Dim WithEvents objConn As ADODB.Connection
' Note how the object name, objConn, is incorporated into the event Sub name
Private Sub objConn_
WillExecute
( Source As String, _
CursorType As ADODB.CursorTypeEnum, _
LockType As ADODB.LockTypeEnum, _
Options As Long _
adStatus As ADODB.EventStatusEnum, _
ByVal pCommand As ADODB.Command )
ByVal pRecordset As ADODB.Recordset )
ByVal pConnection As ADODB.Connection )
' place any code you desire here, for example
If LockType = adLockReadOnly Then
Print "The Lock Type is read-only"
End If
End Sub
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information