通过adodb连接在vb中使用oracle存储过程

时间:2013-10-09 05:58:10

标签: oracle vb6

oracle中的包:

create or replace package pkgsearch as
type mycursor is ref cursor;
procedure acc_search(id in varchar,cur out mycursor);
end pkgsearch;

CREATE OR REPLACE PACKAGE BODY pkgsearch AS
PROCEDURE acc_search (id in varchar,cur out mycursor) IS
BEGIN
OPEN cur FOR SELECT *
FROM account
WHERE accno = 'id';
end acc_search;
end pkgsearch;

此程序包用于搜索将id作为参数传递给过程的帐户记录。 VB中的代码

dim con as new ADODB.connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim param As New ADODB.Parameter
Dim str As String

con.open "dsn=xxxxx;uid=xxxxxx;pwd=xxxxxx"

With cmd
.ActiveConnection = con
.CommandText = "pkgsearch.acc_search"
.CommandType = adCmdStoredProc
Set param = .CreateParameter("id", adVarChar, adParamInput, 10, Text1.Text)
.Parameters.Append param
End With

Set rs = cmd.Execute

Text1.Text = rs.Fields(0).Value
Text2.Text = rs.Fields(1).Value

编辑:

这会产生:

  

运行时错误'-2147217887(80040e21)'; ODBC驱动程序不支持请求的属性。点击调试后,它会突出显示'set rs = cmd.execute'

请提出一些修改建议。

在VB中执行命令后还有其他方法可以使用记录集吗?

提前完成。

1 个答案:

答案 0 :(得分:0)

我不确定使用Oracle,但我认为它与SQL几乎相同。

这就是我用于SQL的内容:

sql = "exec STORED PROCEDURE HERE"
Set RS = ExecuteQuery(sql)
RS.MoveFirst

While not EOF
DO STUFF
RS.MoveNext
Wend

共享模块:

Public connect As New ADODB.Connection
Public cmd As ADODB.command

    Public Function ConnectToDBOpen() As Boolean
        If (connect.State = adStateOpen) Then
            connect.Close
        End If
        connect.CursorLocation = adUSeClient
        connect.Open "CONNECTION INFO HERE"

        ConnectToDBOpen = True
    End Function


    Public Function DisconnectFromDB()

        connect.Close

    End Function


    Public Function ExecuteQuery(ByVal sqlQuery As String) As ADODB.Recordset
        Dim rsOut As ADODB.Recordset
        Set rsOut = New ADODB.Recordset
        Dim recordsAffected As Long


        If ConnectToDBOpen Then
            Dim command
            Set command = New ADODB.command

            With command
                .ActiveConnection = connect
                .CommandText = sqlQuery
                .CommandType = adCmdText
            End With

            rsOut.Open command.Execute(recordsAffected)

            Set ExecuteQuery = rsOut
            Set command = Nothing
            Call DisconnectFromDB
        End If
    End Function