我使用Visual Basic 6连接到Oracle 11g。 是的,我可以成功连接到数据库。 问题是从数据库接收记录集。 我创建了一个如下所示的oracle包:
包装:
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;
/
体:
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;
/
它适用于C#。 我已经测试了。
现在我的Visual Basic 6源代码如下:
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
连接源如下:
tmpDB_Total.Open "Provider=OraOLEDB.Oracle;" _
& "Password=mes123;" _
& "User ID=mes;" _
& "Persist Security Info=True;" _
& "Data Source=stmdev;"
我收到一些关于参数的错误。 错误信息是用韩语写的,所以我不能马上写。 请理解我。 任何人都可以帮我解决这个问题吗?
答案 0 :(得分:2)
你有一个额外的参数。只是不要尝试为第三个参数附加任何内容,它应该可以工作。请注意,您需要设置Cmd.Properties("PLSQLRSet") = TRUE