Metodo Execute

Esegue un comando SQL. Restituisce un oggetto RecordSet per le query SELECT o un numero intero per i comandi che non restituiscono record.

Sintassi

Object.Execute(CommandText, RecordsAffected)

Argomenti:

  • Object: obbligatorio. Sempre il nome dell'oggetto ADODB.Connection.

  • CommandText: obbligatorio. Comando SQL

  • RecordsAffected: facoltativo. Numero di record interessati dai comandi che non restituiscono record

Note

Nell'esempio seguente viene illustrato l'uso del metodo Execute.

Esempio 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