<< Click to Display Table of Contents >> Navigation: ThinBASIC Modules > ADODB > ADODB Module Classes > ADODB_Connection > ADODB_Connection Methods > <ADODB_Connection>.Execute |
Description
Executes the specified query, SQL statement, stored procedure, or provider-specific text.
Syntax
RecordSet = <ADODB_Connection>.Execute (sCommandText [, lRecordsEffected [, lOptions]])
Returns
An optional RecordSet object
Parameters
Name |
Type |
Optional |
Meaning |
sCommandText |
String |
No |
A String value that contains the SQL statement, stored procedure, a URL, or provider-specific text to execute. Optionally, table names can be used but only if the provider is SQL aware. For example if a table name of "Customers" is used, ADO will automatically prepend the standard SQL Select syntax to form and pass "SELECT * FROM Customers" as a Transact-SQL statement to the provider. |
lRecordsEffected |
Variable |
Yes |
A Long variable to which the provider returns the number of records that the operation affected |
lOptions |
Number |
Yes |
A value that indicates how the provider should evaluate the CommandText argument. Can be a bitmask of one or more CommandTypeEnum or ExecuteOptionEnum values. |
Remarks
Using the Execute method on a ADODB_Connection object executes whatever query you pass to the method in the CommandText argument on the specified connection.
If the CommandText argument specifies a row-returning query, any results that the execution generates are stored in a new ADODB_Recordset object.
IMPORTANT: If the command is not intended to return results (for example, an SQL UPDATE query) the provider returns Nothing as long as the option %adExecuteNoRecords is specified; otherwise Execute returns a closed ADODB_Recordset.
Consider usage of <ADODB_Connection>.ExecuteCmd method that is specifically designed to simplify Update/Insert commands.
The returned ADODB_Recordset object is always a read-only, forward-only cursor.
If you need an ADODB_Recordset object with more functionality, first create a ADODB_Recordset object with the desired property settings, then use the ADODB_Recordset object's Open Method to execute the query and return the desired cursor type.
When using <ADODB_Connection>.Execute inside a loop and no recordset is needed, be sure to use %adExecuteNoRecords option otherwise a memory and database resources leak will be generated.
Restrictions
See also
Examples
Uses "Console"
Uses "ADODB"
'---Declare a new pConnection variable and instantiate it in one line
Dim pConn As New ADODB_CONNECTION
pConn.Provider = "Microsoft.Jet.OLEDB.4.0"
pConn.Open(APP_SourcePath & "Biblio.mdb")
PrintL pConn.Provider
Printl pConn.ConnectionString
If pConn.State = %ADSTATEOPEN Then
Dim pRS As New ADODB_RECORDSET
Dim sSql As String
dim nRec as Long
'---
'sSql = "Update Authors set [Year Born] = 2017 Where Au_ID = 1"
sSql = "Select * from Authors order by Au_ID"' Where Au_ID = 1"
PrintL "Query is:", sSql
pRS = pConn.Execute(sSql, nRec)
printl "Records effected (valid only for update queries):", nRec
While not pRS.EOF
printl pRS.Collect("Au_ID"), pRS.Collect("Author")
pRS.MoveNext
Wend
pConn.Close
end If
WaitKey