Skip Headers

Oracle® Objects for OLE Developer's Guide
10g Release 1 (10.1)

Part Number B10118-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Feedback

CreateSQL Method Example

This example demonstrates the use of parameters, the CreateSQL method, the Refresh method, and the SQL property for SqlStmt object. Copy and paste this code into the definition section of a form, then press F5.

Sub Form_Load ()

'Declare variables

Dim OraSession As OraSession

Dim OraDatabase As OraDatabase

Dim OraSqlStmt As OraSQLStmt

'Create the OraSession Object.

Set OraSession = CreateObject("OracleInProcServer.XOraSession")

'Create the OraDatabase Object by opening a connection to Oracle.

Set OraDatabase = OraSession.OpenDatabase("ExampleDb", "scott/tiger", 0&)

OraDatabase.Parameters.Add "EMPNO", 7369, 1

OraDatabase.Parameters("EMPNO").ServerType = 2 'ORATYPE_NUMBER

OraDatabase.Parameters.Add "ENAME", 0, 2

OraDatabase.Parameters("ENAME").ServerType = 1 'ORATYPE_VARCHAR2

Set OraSqlStmt = OraDatabase.CreateSQL("Begin Employee.GetEmpName (:EMPNO, :ENAME); end;", 0&)

'Notice that the SQL statement is NOT modified.

MsgBox OraSqlStmt.SQL

'Should display SMITH

MsgBox OraDatabase.Parameters("ENAME").Value

'Change the value of the empno parameter.

OraDatabase.Parameters("EMPNO").Value = 7499

'Refresh the sqlstmt

OraSqlStmt.Refresh

'Should display ALLEN

MsgBox OraDatabase.Parameters("ENAME").Value

'Notice that the SQL statement is NOT modified.

MsgBox OraSqlStmt.SQL

'Remove the parameter.

OraDatabase.Parameters.Remove ("job")

End Sub