Execute Method for LCConnection
This method executes a statement in connector-specific syntax, for example, an SQL statement for a relational database connector. For example, this method executes a DB2® SQL statement for the purposes of producing a result set.
Defined In
LCConnection
Syntax
count = lcConnection.Execute(statement, destFieldlist)
Parameters
Parameter |
Description |
---|---|
statement |
String. The statement to execute in the syntax defined for the connector. See the documentation for the specific connector for information about the required syntax. |
destFieldList |
Long. LCFieldlist. Fieldlist to contain the metadata of the execute result set. The fields in the result set will be appended to this fieldlist. If the result set metadata is not required, use Nothing. |
Return Value
Value |
Description |
---|---|
count |
Long. Number of records selected or affected by this statement. If this number cannot be determined by the connector, the constant LCCOUNT_UNKNOWN is returned. |
Example
Option Public
Uselsx "*lsxlc"
Sub Initialize
Dim src As New LCConnection ("db2")
Dim fldLst As New LCFieldList
Dim fld As LCField
Dim count As Integer
' set the appropriate properties to connect
src.Database = "Gold"
src.Userid = "JDoe"
src.Password = "xyzzy"
src.Connect
' now connected, we can execute a selection statement
If (src. Execute ("SELECT * from customer", fldLst) = 0) Then
Print "No records were fetched."
End
End If
Set fld = fldLst.Lookup ("CONTACTNAME")
Print "the 'contact names' stored in the table are:"
' fetch each record from the result set
While (src.Fetch (fldLst) > 0)
count = count + 1
Print " record #" & Cstr(count) & " = '" & fld.text(0) & "'"
Wend
If (count = 0) Then Print "No records were fetched."
End Sub
Example Output
The 'contact names' stored in the table are:
record #1 = 'Peter Soames
record #2 = 'Trent Kent'
record #3 = 'Joan Lawrens'