Hi there,
I receive the following message when I run my function that executes an Oracle Stored Procedure:
The OracleParameter is already contained by another OracleParameterCollection
Does anyone know why this is happenning?
Below the code I used:
Private Overloads Function Oracle_ExecuteProcedure(ByVal ProcedureName As String, ByVal Parms As OracleClient.OracleParameter()) As Integer
Dim intRowsAffected As Integer
Dim OracleParm As New OracleClient.OracleParameter
If MyConnection.State <> ConnectionState.Open Then
MyConnection.Open()
End If
'Configure the MySqlCommand object
MySqlCommand = New System.Data.OracleClient.OracleCommand(ProcedureName, MyConnection)
With MySqlCommand
.CommandType = CommandType.StoredProcedure 'Set type to Stored Procedure
.CommandText = ProcedureName 'Specify procedure to run
'Clear any previous parameters from the command object
.Parameters.Clear()
'Loop through parmameter collection, if defined, adding parameters to the command object
If Not (Parms Is Nothing) Then
For Each OracleParm In Parms
MySqlCommand.Parameters.Add(OracleParm)
Next
End If
End With
'Execute the procedure
intRowsAffected = MySqlCommand.ExecuteNonQuery()
Return intRowsAffected 'Return the number of rows affected by procedure
End Function
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim sFiles(2) as String
Dim Parms1(1) As OracleClient.OracleParameter
Dim RowsGenerated As Integer
sFiles(0)="123.txt"
sFiles(1)="abc.txt"
Parms1(0) = New OracleClient.OracleParameter("FILENAME", sFiles(0))
Parms1(1) = New OracleClient.OracleParameter("DATESTR", DATEI)
RowsGenerated = Oracle_ExecuteProcedure("UPDATE_R151BTS", Parms1) 'This one is work fine
Parms1(0) = New OracleClient.OracleParameter("FILENAME", sFiles(1))
RowsGenerated = Oracle_ExecuteProcedure("UPDATE_R153", Parms1) 'This one generates the error
End Sub