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

Using oracle stored procedure in vb through adodb connection(通过adodb连接在vb中使用oracle存储过程)
本文介绍了通过adodb连接在vb中使用oracle存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

oracle 中的包:

Package in 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中的代码

This package is used to search account records where id is passed as paramter to procedure. Code in 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

推荐答案

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

I am not sure about using Oracle but I assume its almost the same as SQL.

这是我用于 SQL 的:

This is what I used for 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

这篇关于通过adodb连接在vb中使用oracle存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)