How to call an Oracle Stored Procedure with Parameters

Posts   
 
    
skyxn3t
User
Posts: 2
Joined: 09-Jun-2012
# Posted on: 03-Aug-2012 04:38:53   

Greetings, as the title says, How to call an **Oracle **Stored Procedure and pass parameters to it?

Here's what I have so far:

Lets say I have a stored procedure called CUSTOMER_INFO which has 3 INput parameters and returns an OUTput value.



DataSet ds = new DataSet();

SqlParameter[] parameters = new SqlParameter[3];

parameters[0] = new SqlParameter("@inParameter1", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 18, 0, "", DataRowVersion.Current, Parameter1);
parameters[1] = new SqlParameter("@inParameter2", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 18, 0, "", DataRowVersion.Current, Parameter2);
 parameters[2] = new SqlParameter("@inParameter3", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 18, 0, "", DataRowVersion.Current, Parameter3);

 using (IDataAccessAdapter adapter = DataAccessManager.CreateAdapter())
{
      adapter.CallRetrievalStoredProcedure("CUSTOMER_INFO", parameters, ds);
}


But after the "CallRetrievalStoredProcedure" is executed the following exception is thrown:

Unable to cast object of type 'System.Data.SqlClient.SqlParameter' to type 'Oracle.DataAccess.Client.OracleParameter'.

Is this the correct way to call a stored procedure and pass parameters to it?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Aug-2012 07:07:06   

The error you see if because you are using SqlClient classes to call Oracle SPs, which will fail always. Even if you make it to work with OracleCilent classes, you are doing too much work. LLBLGen can do the hard work for you wink

The easiest way to work with StoredProcedures is:

  1. Import the SPs metadata into your project, so LLBLGen knows which are the SPs you will use in your code. See the step 3 of the Relational Model Data Retrieval Wizard for more info.

  2. After you generate the code, you can use those calls directly. See Calling a Stored Procedure for more info.

David Elizondo | LLBLGen Support Team