473,569 Members | 3,035 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(s Select ,
cnn);
selectCommand.C ommandType = CommandType.Sto redProcedure;
OracleParameter prm1 = new OracleParameter ();
prm1 = selectCommand.P arameters.Add(" prm_1",
OracleType.Int1 6);
prm1.Direction = ParameterDirect ion.Output;
prm1.Value = 0;
OracleDataReade r dr = selectCommand.E xecuteReader();
DataGrid1.DataS ource = dr;
DataGrid1.DataB ind();

Thanks Jeff.
Nov 17 '05 #1
4 5565
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.Ora cleClient;
....
myOrclConnectio n = new System.Data.Ora cleClient.Oracl eConnection("Da ta
Source=;User ID=scott;Passwo rd=tiger;");
myOracleCommand = New OracleClient.Or acleCommand();
myOracleCommand .CommandType = CommandType.Sto redProcedure;
myOracleCommand .CommandText = "DRM.PKG.LI ST";
myOracleCommand .Connection = myOrclConnectio n;
myOracleCommand .Parameters.Add ("prm_1", OracleType.Int1 6);
myOracleCommand .Parameters("pr m_1").Directio n = ParameterDirect ion.Output;
myOracleCommand .Parameters.Add ("p_ref_cursor" , OracleType.Curs or);
myOracleCommand .Parameters("p_ ref_cursor").Di rection =
ParameterDirect ion.Output;
OracleDataReade r dr =
myOracleCommand .ExecuteReader( CommandBehavior .CloseConnectio n);
DataGrid1.DataS ource = dr;
DataGrid1.DataB ind();

-Steve Jansen

"Jeff" <ja*******@hotm ail.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(s Select ,
cnn);
selectCommand.C ommandType = CommandType.Sto redProcedure;
OracleParameter prm1 = new OracleParameter ();
prm1 = selectCommand.P arameters.Add(" prm_1",
OracleType.Int1 6);
prm1.Direction = ParameterDirect ion.Output;
prm1.Value = 0;
OracleDataReade r dr = selectCommand.E xecuteReader();
DataGrid1.DataS ource = dr;
DataGrid1.DataB ind();

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 ParameterDirect ion
Public Value As Object
Public Size As Integer
Public Sub New(ByVal Name As String, _
ByVal Type As OracleType, _
ByVal Direction As ParameterDirect ion, _
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 ExecuteProcedur e _
(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 OracleConnectio n = New OracleConnectio n
Dim cmdCommand As OracleCommand = New OracleCommand
cmdCommand.Conn ection = conConnection
Dim da As OracleDataAdapt er = Nothing
Dim ds As DataSet = Nothing

'// ConnectionStrin g form:
'// "Data Source=DEVELOP; User ID=User1;Passwo rd=PWD"
conConnection.C onnectionString = ConnectionStrin g()

cmdCommand.Comm andType = CommandType.Sto redProcedure
cmdCommand.Comm andText = ProcName

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

If cp.Type = OracleType.Curs or Then wantCursors = True
If cp.Direction = ParameterDirect ion.ReturnValue Then _
returnParamName = cp.Name
Next

'// excute the command
conConnection.O pen()
If wantCursors Then
da = New OracleDataAdapt er(cmdCommand)
ds = New DataSet("result s")
da.Fill(ds, "results")
Else
cmdCommand.Exec uteNonQuery()
End If
conConnection.C lose()

'update any in/out parameters here
For Each cp In Args
If cp.Direction = ParameterDirect ion.InputOutput Or _
cp.Direction = ParameterDirect ion.Output Then
If wantCursors And cp.Type = OracleType.Curs or Then
cp.Value = ds
Else
cp.Value = cmdCommand.Para meters(cp.Name) .Value
End If
End If
Next

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

Catch e As Exception
If conConnection.S tate <> ConnectionState .Closed Then _
conConnection.C lose()
Throw e
Finally
If conConnection.S tate <> ConnectionState .Closed Then _
conConnection.C lose()
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 ParameterDirect ion
Public Value As Object
Public Size As Integer
Public Sub New(ByVal Name As String, _
ByVal Type As OracleType, _
ByVal Direction As ParameterDirect ion, _
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 ExecuteProcedur e _
(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 OracleConnectio n = New OracleConnectio n
Dim cmdCommand As OracleCommand = New OracleCommand
cmdCommand.Conn ection = conConnection
Dim da As OracleDataAdapt er = Nothing
Dim ds As DataSet = Nothing

'// ConnectionStrin g form:
'// "Data Source=DEVELOP; User ID=User1;Passwo rd=PWD"
conConnection.C onnectionString = ConnectionStrin g()

cmdCommand.Comm andType = CommandType.Sto redProcedure
cmdCommand.Comm andText = ProcName

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

If cp.Type = OracleType.Curs or Then wantCursors = True
If cp.Direction = ParameterDirect ion.ReturnValue Then _
returnParamName = cp.Name
Next

'// excute the command
conConnection.O pen()
If wantCursors Then
da = New OracleDataAdapt er(cmdCommand)
ds = New DataSet("result s")
da.Fill(ds, "results")
Else
cmdCommand.Exec uteNonQuery()
End If
conConnection.C lose()

'update any in/out parameters here
For Each cp In Args
If cp.Direction = ParameterDirect ion.InputOutput Or _
cp.Direction = ParameterDirect ion.Output Then
If wantCursors And cp.Type = OracleType.Curs or Then
cp.Value = ds
Else
cp.Value = cmdCommand.Para meters(cp.Name) .Value
End If
End If
Next

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

Catch e As Exception
If conConnection.S tate <> ConnectionState .Closed Then _
conConnection.C lose()
Throw e
Finally
If conConnection.S tate <> ConnectionState .Closed Then _
conConnection.C lose()
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 ParameterDirect ion
Public Value As Object
Public Size As Integer
Public Sub New(ByVal Name As String, _
ByVal Type As OracleType, _
ByVal Direction As ParameterDirect ion, _
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 ExecuteProcedur e _
(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 OracleConnectio n = New OracleConnectio n
Dim cmdCommand As OracleCommand = New OracleCommand
cmdCommand.Conn ection = conConnection
Dim da As OracleDataAdapt er = Nothing
Dim ds As DataSet = Nothing

'// ConnectionStrin g form:
'// "Data Source=DEVELOP; User ID=User1;Passwo rd=PWD"
conConnection.C onnectionString = ConnectionStrin g()

cmdCommand.Comm andType = CommandType.Sto redProcedure
cmdCommand.Comm andText = ProcName

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

If cp.Type = OracleType.Curs or Then wantCursors = True
If cp.Direction = ParameterDirect ion.ReturnValue Then _
returnParamName = cp.Name
Next

'// excute the command
conConnection.O pen()
If wantCursors Then
da = New OracleDataAdapt er(cmdCommand)
ds = New DataSet("result s")
da.Fill(ds, "results")
Else
cmdCommand.Exec uteNonQuery()
End If
conConnection.C lose()

'update any in/out parameters here
For Each cp In Args
If cp.Direction = ParameterDirect ion.InputOutput Or _
cp.Direction = ParameterDirect ion.Output Then
If wantCursors And cp.Type = OracleType.Curs or Then
cp.Value = ds
Else
cp.Value = cmdCommand.Para meters(cp.Name) .Value
End If
End If
Next

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

Catch e As Exception
If conConnection.S tate <> ConnectionState .Closed Then _
conConnection.C lose()
Throw e
Finally
If conConnection.S tate <> ConnectionState .Closed Then _
conConnection.C lose()
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
1177
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. 282.1073834719.12720.python-list%40python.org&rnum=1&prev=/groups%3Fsourceid %3Dmozclient%26ie%3Dutf-8%26oe%3Dutf-8%26q%3Dpython%2Boracle%2Bmysql The tables in Oracle and Mysql are...
1
4145
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 problem is that the server doesn't have DBI and DBI::Oracle packages and the owner's server doesn't want to install the packages because he thinks that...
4
19974
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
4366
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 eventually the PL/SQL packages in Oracle. My application is mainly built by differenct PL/SQL packages in Oracle. The packages build the html page...
11
10734
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 execute in the database server with better performance? Please advise good references for Oracle stored procedures also. thanks!!
56
4899
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 which are not supported.
0
1081
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 in design mode when I'm in the SALDataAdapter wizard, trying to locate the stored procedure to select it, and generate the parameters, etc, I can see...
1
2230
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#. The majority of the database calls are in stored procedures. The error that is thrown by Oracle is "ORA-6550: line 0, column 0:PLS:00907: cannot load...
0
1461
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 both in these and I've pass these credentials from a config file in my application. But the SQL to SQL package works perfectly, and it will takes the...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.