这些都是去年的代码,怕遗忘,也为了方便查找,所以放到这里保存!
建立工程就不说了
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语句来执行,并返回结果。但是手头没有代码,也就写到这里了