superwei

导航

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

统计

常用链接

留言簿(4)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜

VB.NET 2003 调用Oracle的存储过程并返回游标值(原创)

这些都是去年的代码,怕遗忘,也为了方便查找,所以放到这里保存!
建立工程就不说了
1、新建一个Module,添加代码如下:

    Public Function runProduce(ByVal _arrayPro() As OracleParameter, ByVal _strProName As String, ByVal _strCon As OracleClient.OracleConnection)
        Dim total As Integer
        Dim ocmd As New OracleCommand(_strProName, _strCon)
        Dim oda As New OracleDataAdapter(ocmd)
        Dim dsSales As New DataSet

        ocmd.CommandType = CommandType.StoredProcedure

        Dim errcdPara As New OracleParameter
        With errcdPara
            .ParameterName = "P_ERRCD"
            .OracleType = OracleType.Char
            .Size = 88
            .Direction = ParameterDirection.InputOutput
            .Value = ""
        End With
        Dim errMsgPara As New OracleParameter
        With errMsgPara
            .ParameterName = "P_ERRMSG"
            .OracleType = OracleType.VarChar
            .Size = 88
            .Direction = ParameterDirection.InputOutput
            .Value = ""
        End With

        ocmd.Parameters.Add(errcdPara)
        ocmd.Parameters.Add(errMsgPara)
        For total = UBound(_arrayPro) To 0 Step -1
            ocmd.Parameters.Add(_arrayPro(total))
        Next

        Try
            oda.Fill(dsSales)
        Catch exp As Exception
            'MessageBox.Show(exp.Message, MessageBoxButtons.OK, _
            '    MessageBoxIcon.Error)
            MsgBox(exp.Message)
            Exit Function
        End Try

        _strCon.Close()
        Return dsSales
    End Function

参数:_arrayPro() 存储过程的参数;_strProName 存储过程名;_strCon Oracle的连接对象

2、执行代码

        Dim strConn As oracConnection = oracConn()
        Dim arrayPro(1) As OracleParameter

        Dim sorPara As New OracleParameter
        With sorPara
            .ParameterName = "SOR_SHIWAKE"
            .OracleType = OracleType.Cursor
            .Direction = ParameterDirection.Output
            .Value = ""
        End With
        arrayPro(0) = sorPara

        Dim salePara As New OracleParameter
        With salePara
            .ParameterName = "P_SALEYMD"
            .OracleType = OracleType.VarChar
            .Direction = ParameterDirection.Input
            .Value = strInput
        End With
        arrayPro(1) = salePara

        If strConn.isConn = True Then
            Dim dsDataSet As DataSet = runProduce(arrayPro, @produceName, conn)
        End If

.NET调用存储过程有两种方法,以上是其中一种比较简便的方法(自认为),
另一种也简单,就是做成一条SQL语句来执行,并返回结果。但是手头没有代码,也就写到这里了



posted on 2007-09-27 16:05 小辞猬 阅读(1055) 评论(0)  编辑  收藏 所属分类: DoNet


只有注册用户登录后才能发表评论。


网站导航: