Article ID: 167225
Article Last Modified on 3/2/2005
CREATE TABLE rdooracle (
item_number NUMBER(3) PRIMARY KEY,
depot_number NUMBER(3));
CREATE OR REPLACE PROCEDURE rdoinsert
(insnum IN NUMBER, outnum OUT NUMBER)
IS
BEGIN
INSERT INTO rdooracle
(Item_Number, Depot_Number)
VALUES
(insnum, 16);
outnum := insnum/2;
END;
Control Name Text/Caption
---------------------------------
Button cmdCheck Check
Button cmdSend Send
Text Box txtInput
Label lblInput Input:
Option Explicit
Dim Cn As rdoConnection
Dim En As rdoEnvironment
Dim CPw As rdoQuery
Dim Rs As rdoResultset
Dim Conn As String
Dim QSQL As String
Dim Response As String
Dim Prompt As String
Private Sub cmdCheck_Click()
QSQL = "Select Item_Number, Depot_Number From rdooracle Where " _
& "item_number =" & txtInput.Text
Set Rs = Cn.OpenResultset(QSQL, rdOpenStatic, , rdExecDirect)
Prompt = "Item_Number = " & Rs(0) & ". Depot_Number = " _
& Rs(1) & "."
Response = MsgBox(Prompt, , "Query Results")
Rs.Close
End Sub
Private Sub cmdSend_Click()
CPw(0) = Val(txtInput.Text)
CPw.Execute
Prompt = "Return value from stored procedure is " & CPw(1) & "."
Response = MsgBox(Prompt, , "Stored Procedure Result")
End Sub
Private Sub Form_Load()
Conn = "UID=;PWD=;driver={Microsoft ODBC Driver for Oracle};" _
& "CONNECTSTRING=MyOracle;"
Set En = rdoEnvironments(0)
Set Cn = En.OpenConnection("", rdDriverPrompt, False, Conn)
QSQL = "{call rdoinsert(?,?)}"
Set CPw = Cn.CreateQuery("", QSQL)
End Sub
Private Sub Form_Unload(Cancel As Integer)
En.Close
End Sub
Private Sub Form_Load()
Conn = "UID=;PWD=;driver={Microsoft ODBC Driver for Oracle};" _
& "CONNECTSTRING=MyOracle;"
Set En = rdoEnvironments(0)
Set Cn = En.OpenConnection("", rdDriverPrompt, False, Conn)
QSQL = "{call rdoinsert(?,?)}"
Set CPw = Cn.CreateQuery("", QSQL)
End Sub
Note that you are not using the rdPreparedStatement object. This object has
been replaced by the rdoQuery object. This is new for RDO 2.0. Also, with
RDO 2.0, you do not need to explicitly create a connection object as is
done in this project. You can create a stand-alone query object that is not
specifically associated with a connection. To learn more about this
functionality, look up the rdoQuery Object in the Visual Basic 5.0
Enterprise edition Help file.
Conn = "UID=;PWD=;driver={Microsoft ODBC Driver for Oracle};" _
& "CONNECTSTRING=MyOracle;"
The most important part of this connect string is the "CONNECTSTRING"
keyword. It is used only by the Microsoft ODBC Driver for Oracle. For
Microsoft SQL Server 6.5, you use the keyword "SERVER." The string assigned
to CONNECTSTRING is the Database Alias that you set up in SQL*Net. This is
the only difference in the connect string when connecting to an Oracle
database. All of the other parameters operate as described in the Help file
(under rdoConnection Object) for Visual Basic 5.0 Enterprise edition. As
stated in the Help file, for a connection, you do not specify a DSN in the
connect string.
QSQL = "{call rdoinsert(?,?)}"
Set CPw = Cn.CreateQuery("", QSQL)
With Oracle, you cannot specify a return value for a stored procedure call
as you can with Microsoft SQL Server 6.5; you must use stored procedures
that have output parameters as noted earlier in this article. The parameter
placeholders in the QSQL string are denoted by a "?" and referenced in the
order they in which they appear in the string. For more information on the
use of parameter placeholders in the rdoQuery object, refer to the
rdoParameter object in the Visual Basic 5.0 Enterprise edition Help file.
Additional query words: Oracle RDO Stored Procedure
Keywords: kbhowto kboracle KB167225