473,508 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling Oracle Packages

Help!!

I'm trying to convert a visual basic stand alone program
into a Web Program using C#. There are a lot of Oracle
packages already written that I am trying to use
(unsuccessfully). Can someone point me in the right
direction on how to call an Oracle package into a
datagrid??
something like:

cnn.Open();
string sSelect = "{CALL DRM.PKG.LIST(?)}";
OracleCommand selectCommand = new OracleCommand(sSelect ,
cnn);
selectCommand.CommandType = CommandType.StoredProcedure;
OracleParameter prm1 = new OracleParameter();
prm1 = selectCommand.Parameters.Add("prm_1",
OracleType.Int16);
prm1.Direction = ParameterDirection.Output;
prm1.Value = 0;
OracleDataReader dr = selectCommand.ExecuteReader();
DataGrid1.DataSource = dr;
DataGrid1.DataBind();

Thanks Jeff.
Nov 17 '05 #1
4 5556
Jeff,

You most likely need to explictily add the REF CURSOR output parameter.
ADO, but not ADO.NET, allowed you to specify the "PLSQLRSet=1" connection
string option to have the Command object automatically do this for you when
populating an ADO Recordset.

This code should work, assuming you have an OUTPUT parameter named
p_ref_cursor that is your own package type that is a REF CURSOR.

using System.Data.OracleClient;
....
myOrclConnection = new System.Data.OracleClient.OracleConnection("Data
Source=;User ID=scott;Password=tiger;");
myOracleCommand = New OracleClient.OracleCommand();
myOracleCommand.CommandType = CommandType.StoredProcedure;
myOracleCommand.CommandText = "DRM.PKG.LIST";
myOracleCommand.Connection = myOrclConnection;
myOracleCommand.Parameters.Add("prm_1", OracleType.Int16);
myOracleCommand.Parameters("prm_1").Direction = ParameterDirection.Output;
myOracleCommand.Parameters.Add("p_ref_cursor", OracleType.Cursor);
myOracleCommand.Parameters("p_ref_cursor").Directi on =
ParameterDirection.Output;
OracleDataReader dr =
myOracleCommand.ExecuteReader(CommandBehavior.Clos eConnection);
DataGrid1.DataSource = dr;
DataGrid1.DataBind();

-Steve Jansen

"Jeff" <ja*******@hotmail.com> wrote in message
news:34****************************@phx.gbl...
Help!!

I'm trying to convert a visual basic stand alone program
into a Web Program using C#. There are a lot of Oracle
packages already written that I am trying to use
(unsuccessfully). Can someone point me in the right
direction on how to call an Oracle package into a
datagrid??
something like:

cnn.Open();
string sSelect = "{CALL DRM.PKG.LIST(?)}";
OracleCommand selectCommand = new OracleCommand(sSelect ,
cnn);
selectCommand.CommandType = CommandType.StoredProcedure;
OracleParameter prm1 = new OracleParameter();
prm1 = selectCommand.Parameters.Add("prm_1",
OracleType.Int16);
prm1.Direction = ParameterDirection.Output;
prm1.Value = 0;
OracleDataReader dr = selectCommand.ExecuteReader();
DataGrid1.DataSource = dr;
DataGrid1.DataBind();

Thanks Jeff.

Nov 17 '05 #2
Well, we are not using C# in house, we are working in VB right now. But
this is the Sub we use for calling procedures in packages (hopefully you
shouldnt have too much trouble converting it). It makes some assumptions
about Procedure returns and such based on our business rules, so you may
need to change it a bit, but weve had no problems with it.

'// BEGIN CODE ================================================== =======
#Region " Helper Class "
Public Class clsParamDef
Public Name As String
Public Type As OracleType
Public Direction As ParameterDirection
Public Value As Object
Public Size As Integer
Public Sub New(ByVal Name As String, _
ByVal Type As OracleType, _
ByVal Direction As ParameterDirection, _
Optional ByVal Value As Object = Nothing, _
Optional ByVal Size As Integer = Nothing)
Me.Name = Name
Me.Type = Type
Me.Direction = Direction
Me.Value = Value
Me.Size = Size
End Sub
End Class
#End Region

Public Module DB
Public Function ExecuteProcedure _
(ByVal ProcName As String, ByRef Args() As clsParamDef) As Object

Try
'// Name of RETURN parameter if there is one
Dim returnParamName As String = ""
'// Remember if there are any OUTPUT params
Dim wantCursors As Boolean = False
Dim conConnection As OracleConnection = New OracleConnection
Dim cmdCommand As OracleCommand = New OracleCommand
cmdCommand.Connection = conConnection
Dim da As OracleDataAdapter = Nothing
Dim ds As DataSet = Nothing

'// ConnectionString form:
'// "Data Source=DEVELOP;User ID=User1;Password=PWD"
conConnection.ConnectionString = ConnectionString()

cmdCommand.CommandType = CommandType.StoredProcedure
cmdCommand.CommandText = ProcName

'// set up the parameters on the command object
cmdCommand.Parameters.Clear()
Dim cp As clsParamDef
For Each cp In Args
cmdCommand.Parameters.Add(cp.Name, cp.Type).Direction _
= cp.Direction
cmdCommand.Parameters(cp.Name).Value = cp.Value
If Not IsNothing(cp.Size) AndAlso cp.Size > 0 Then _
cmdCommand.Parameters(cp.Name).Size = cp.Size

If cp.Type = OracleType.Cursor Then wantCursors = True
If cp.Direction = ParameterDirection.ReturnValue Then _
returnParamName = cp.Name
Next

'// excute the command
conConnection.Open()
If wantCursors Then
da = New OracleDataAdapter(cmdCommand)
ds = New DataSet("results")
da.Fill(ds, "results")
Else
cmdCommand.ExecuteNonQuery()
End If
conConnection.Close()

'update any in/out parameters here
For Each cp In Args
If cp.Direction = ParameterDirection.InputOutput Or _
cp.Direction = ParameterDirection.Output Then
If wantCursors And cp.Type = OracleType.Cursor Then
cp.Value = ds
Else
cp.Value = cmdCommand.Parameters(cp.Name).Value
End If
End If
Next

mobjLastEx = Nothing
'// return the return value if there is one
If returnParamName <> "" Then _
Return cmdCommand.Parameters(returnParamName).Value

Catch e As Exception
If conConnection.State <> ConnectionState.Closed Then _
conConnection.Close()
Throw e
Finally
If conConnection.State <> ConnectionState.Closed Then _
conConnection.Close()
End Try
End Function
End Module
'// END CODE ================================================== =========

Nov 17 '05 #3
Well, we are not using C# in house, we are working in VB right now. But
this is the Sub we use for calling procedures in packages (hopefully you
shouldnt have too much trouble converting it). It makes some assumptions
about Procedure returns and such based on our business rules, so you may
need to change it a bit, but weve had no problems with it.

'// BEGIN CODE ================================================== =======
#Region " Helper Class "
Public Class clsParamDef
Public Name As String
Public Type As OracleType
Public Direction As ParameterDirection
Public Value As Object
Public Size As Integer
Public Sub New(ByVal Name As String, _
ByVal Type As OracleType, _
ByVal Direction As ParameterDirection, _
Optional ByVal Value As Object = Nothing, _
Optional ByVal Size As Integer = Nothing)
Me.Name = Name
Me.Type = Type
Me.Direction = Direction
Me.Value = Value
Me.Size = Size
End Sub
End Class
#End Region

Public Module DB
Public Function ExecuteProcedure _
(ByVal ProcName As String, ByRef Args() As clsParamDef) As Object

Try
'// Name of RETURN parameter if there is one
Dim returnParamName As String = ""
'// Remember if there are any OUTPUT params
Dim wantCursors As Boolean = False
Dim conConnection As OracleConnection = New OracleConnection
Dim cmdCommand As OracleCommand = New OracleCommand
cmdCommand.Connection = conConnection
Dim da As OracleDataAdapter = Nothing
Dim ds As DataSet = Nothing

'// ConnectionString form:
'// "Data Source=DEVELOP;User ID=User1;Password=PWD"
conConnection.ConnectionString = ConnectionString()

cmdCommand.CommandType = CommandType.StoredProcedure
cmdCommand.CommandText = ProcName

'// set up the parameters on the command object
cmdCommand.Parameters.Clear()
Dim cp As clsParamDef
For Each cp In Args
cmdCommand.Parameters.Add(cp.Name, cp.Type).Direction _
= cp.Direction
cmdCommand.Parameters(cp.Name).Value = cp.Value
If Not IsNothing(cp.Size) AndAlso cp.Size > 0 Then _
cmdCommand.Parameters(cp.Name).Size = cp.Size

If cp.Type = OracleType.Cursor Then wantCursors = True
If cp.Direction = ParameterDirection.ReturnValue Then _
returnParamName = cp.Name
Next

'// excute the command
conConnection.Open()
If wantCursors Then
da = New OracleDataAdapter(cmdCommand)
ds = New DataSet("results")
da.Fill(ds, "results")
Else
cmdCommand.ExecuteNonQuery()
End If
conConnection.Close()

'update any in/out parameters here
For Each cp In Args
If cp.Direction = ParameterDirection.InputOutput Or _
cp.Direction = ParameterDirection.Output Then
If wantCursors And cp.Type = OracleType.Cursor Then
cp.Value = ds
Else
cp.Value = cmdCommand.Parameters(cp.Name).Value
End If
End If
Next

mobjLastEx = Nothing
'// return the return value if there is one
If returnParamName <> "" Then _
Return cmdCommand.Parameters(returnParamName).Value

Catch e As Exception
If conConnection.State <> ConnectionState.Closed Then _
conConnection.Close()
Throw e
Finally
If conConnection.State <> ConnectionState.Closed Then _
conConnection.Close()
End Try
End Function
End Module
'// END CODE ================================================== =========

Nov 17 '05 #4
Well, we are not using C# in house, we are working in VB right now. But
this is the Sub we use for calling procedures in packages (hopefully you
shouldnt have too much trouble converting it). It makes some assumptions
about Procedure returns and such based on our business rules, so you may
need to change it a bit, but weve had no problems with it.

'// BEGIN CODE ================================================== =======
#Region " Helper Class "
Public Class clsParamDef
Public Name As String
Public Type As OracleType
Public Direction As ParameterDirection
Public Value As Object
Public Size As Integer
Public Sub New(ByVal Name As String, _
ByVal Type As OracleType, _
ByVal Direction As ParameterDirection, _
Optional ByVal Value As Object = Nothing, _
Optional ByVal Size As Integer = Nothing)
Me.Name = Name
Me.Type = Type
Me.Direction = Direction
Me.Value = Value
Me.Size = Size
End Sub
End Class
#End Region

Public Module DB
Public Function ExecuteProcedure _
(ByVal ProcName As String, ByRef Args() As clsParamDef) As Object

Try
'// Name of RETURN parameter if there is one
Dim returnParamName As String = ""
'// Remember if there are any OUTPUT params
Dim wantCursors As Boolean = False
Dim conConnection As OracleConnection = New OracleConnection
Dim cmdCommand As OracleCommand = New OracleCommand
cmdCommand.Connection = conConnection
Dim da As OracleDataAdapter = Nothing
Dim ds As DataSet = Nothing

'// ConnectionString form:
'// "Data Source=DEVELOP;User ID=User1;Password=PWD"
conConnection.ConnectionString = ConnectionString()

cmdCommand.CommandType = CommandType.StoredProcedure
cmdCommand.CommandText = ProcName

'// set up the parameters on the command object
cmdCommand.Parameters.Clear()
Dim cp As clsParamDef
For Each cp In Args
cmdCommand.Parameters.Add(cp.Name, cp.Type).Direction _
= cp.Direction
cmdCommand.Parameters(cp.Name).Value = cp.Value
If Not IsNothing(cp.Size) AndAlso cp.Size > 0 Then _
cmdCommand.Parameters(cp.Name).Size = cp.Size

If cp.Type = OracleType.Cursor Then wantCursors = True
If cp.Direction = ParameterDirection.ReturnValue Then _
returnParamName = cp.Name
Next

'// excute the command
conConnection.Open()
If wantCursors Then
da = New OracleDataAdapter(cmdCommand)
ds = New DataSet("results")
da.Fill(ds, "results")
Else
cmdCommand.ExecuteNonQuery()
End If
conConnection.Close()

'update any in/out parameters here
For Each cp In Args
If cp.Direction = ParameterDirection.InputOutput Or _
cp.Direction = ParameterDirection.Output Then
If wantCursors And cp.Type = OracleType.Cursor Then
cp.Value = ds
Else
cp.Value = cmdCommand.Parameters(cp.Name).Value
End If
End If
Next

mobjLastEx = Nothing
'// return the return value if there is one
If returnParamName <> "" Then _
Return cmdCommand.Parameters(returnParamName).Value

Catch e As Exception
If conConnection.State <> ConnectionState.Closed Then _
conConnection.Close()
Throw e
Finally
If conConnection.State <> ConnectionState.Closed Then _
conConnection.Close()
End Try
End Function
End Module
'// END CODE ================================================== =========

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1173
by: duikboot | last post by:
Hello all, I still can't convert Oracle tables to a Mysql database. See thread: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&threadm=mailman....
1
4136
by: ulloa | last post by:
Hi. My name is Randall and I am from Costa Rica. I have a little problem. I did an application using Perl, DBI and DBI::Oracle, and now I have to upload my application in an Unix server. The...
4
19967
by: susmita_ganguly | last post by:
Hi I am trying to upgrade from oracle 8i to oracle 9i on the same server ..I don't know much abt migration . Can anyone help me out. Thanks. Susmita
4
4358
by: Wilson | last post by:
I am currently running Oracle 8i with Apache setup in a 4-CPUs Windows 2000 Server. Users on their workstations connect to Oracle through Internet Explorer which accesses Apache's DAD object and...
11
10714
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
56
4888
by: Ashish Patankar | last post by:
I want to migrate my Oracle 10g database to Db2. I want some documentation for the comparision between these to databases. I also want to know which features of Oracle 10g are supported by Db2 and...
0
1078
by: Richard | last post by:
Hi, I have in VB ASP.NET design mode, a SQLDataSource and I need to connect it to a stored procedure in Oracle 9i, but this stored procedure is inside an Oracle package. The problem is that...
1
2223
by: =?Utf-8?B?U3VzYW4=?= | last post by:
The database team just patched the Oracle database with the latest and greatest security patch. Since they patched it, my application has not been stable. My application uses ODP 10.1.0.4 and C#....
0
1455
by: sandeepthomas | last post by:
Friends, I'm in a big issue now. I have to execute some dts packages usig VB.NET. So I've created the packages(one for sql to sql, one for sql to oracle) and declare the necessary global variables...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.