Domanda

I am using Visual Basic 6 to connect to Oracle 11g. Yes, I can successfully connect to the database. The problem is to receive the recordsets from the database. I have created an oracle package like below:

Package:

CREATE OR REPLACE PACKAGE PKG_BASECODE AS

TYPE T_CURSOR IS REF CURSOR;

--// customer
PROCEDURE CustomerCode (
    I_CUST_CODE          IN VARCHAR2
    , I_CUST_NAME        IN VARCHAR2
    , customer_cursor    OUT T_CURSOR
);

END PKG_BASECODE;
/

Body:

CREATE OR REPLACE PACKAGE BODY PKG_BASECODE AS

--// customer
PROCEDURE CustomerCode (
    I_CUST_CODE          IN VARCHAR2
    , I_CUST_NAME        IN VARCHAR2
    , customer_cursor    OUT T_CURSOR
)
IS
    BEGIN
    OPEN customer_cursor FOR
    SELECT  CUST_CODE      AS KEYVALUE
            , CUST_NAME    AS DATAVALUE
    FROM    CUSTOMER_MASTER
    WHERE   CUST_CODE      LIKE I_CUST_CODE || '%'
    AND     CUST_NAME      LIKE I_CUST_NAME || '%'
    ORDER BY CUST_NAME ASC
    ;
    END CustomerCode;


END PKG_BASECODE;
/

It works great with C#. I have already tested.

Now I have my Visual Basic 6 source codes below:

Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim input1 As ADODB.Parameter
Dim input2 As ADODB.Parameter
Dim output1 As ADODB.Parameter
Set cmd = CreateObject("ADODB.Command")
With cmd
    .ActiveConnection = tmpDB_Total

    .CommandText = "PKG_BASECODE.CustomerCode"
    .CommandType = adCmdStoredProc

    .Parameters.Append .CreateParameter("I_CUST_CODE", adVarChar, adParamInput, 10, "")
    .Parameters.Append .CreateParameter("I_CUST_NAME", adVarChar, adParamInput, 50, "")
    .Parameters.Append .CreateParameter("CustomerCode", adVarChar, adParamReturnValue)
    Set rst = .Execute
End With

If Not rst.BOF And Not rst.EOF Then
    Do Until rst.EOF
        Debug.Print rst.Fields(1).Value & "," & rst.Fields(0).Value
        rst.MoveNext
    Loop
End If

And the connection source is below:

tmpDB_Total.Open "Provider=OraOLEDB.Oracle;" _
                 & "Password=mes123;" _
                 & "User ID=mes;" _
                 & "Persist Security Info=True;" _
                 & "Data Source=stmdev;"

And I receive an error something about parameters. The error message is written in Korean language, so I cannot write straight away. Please understand me. Could anyone help me with this problem?

È stato utile?

Soluzione

You've got an extra parameter in there. Just don't try to append anything for that third parameter, and it should work. Note that you will need to set Cmd.Properties("PLSQLRSet") = TRUE

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top