Execute Method

Executes a SQL Command. It returns a RecordSet object for SELECT queries or an Integer for commands that do not return records.

Syntax

Object.Execute(CommandText, RecordsAffected)

Arguments:

  • Object: Required. Always the name of ADODB Connection object.

  • CommandText: Required. SQL Command

  • RecordsAffected: Optional. Number of records affected for commands that do not return records

Remarks

The following example illustrates the use of the Execute method.

Example 1:


'Create ADODB.Connection Object
Dim ConnObj   ' Create a variable.
Set ConnObj = CreateObject("ADODB.Connection")
ConnObj.Open("ConnectionString") 'Creates DB Connection by Using Connection String

Dim RecSetObj
Dim CmdTxt
CmdTxt = "SELECT * FROM EMPLOYEE_DETAILS"
Set RecSetObj = ConnObj.Execute(CmdTxt) 'Returns RecordSet

Dim RecAffected
CmdTxt = "UPDATE EMPLOYEE_DETAILS SET SALARY= 10000 WHERE LEVEL = 5"
ConnObj.BeginTrans()
ConnObj.Execute CmdTxt, RecAffected 'RecAffected filled with number of records updated
ConnObj.CommitTrans()

RecSetObj.Close()
ConnObj.Close()
Set RecSetObj = Nothing
Set ConnObj = Nothing