Page 1 of 1

Need help New C# and OraDirect.net StoredProcedures in Code

Posted: Thu 07 Apr 2005 16:56
by pbright
I want to use a stored procedure created all in code inside a class… I’ve looked at the examples and all of them use the controls dropped on form at design time … however I want to use runtime created objects.

I’ve gotten the stored procedure listed below to work in the visual studio by connecting the control and pre-entering parameter values to pass back to the stored procedure then hitting the execute button …..and it work great…. so the stored procedure is working with Oradirect...

I'm new to c# .. so Now I want to do everything in code…..

Here is the stored procedure that I want to call and the only required field is the P_Transaction_Number. So in my code example below how do I set that value and execute the stored procedure.

CREATE PROCEDURE CREATEORDER

(

p_TRANSACTION_NUMBER BNAPLUS_ORDERS_TBL.TRANSACTION_NUMBER%TYPE

is

begin

INSERT INTO BNAPLUS_ORDERS_TBL

(
TRANSACTION_NUMBER
)

VALUES (

p_Transaction_number

);

end;





In my code I have the following so far:



OracleConnection Connection = new OracleConnection(
ClearConnectionString );

Connection.Open();
OracleCommand Command = new OracleCommand();
Command.Connection = Connection;
Command.CommandText = "CREATEORDER";
Command.CommandType = System.Data.CommandType.StoredProcedure;

(1) How do I add a value in code to pass in Command.Parameters.????

For example I want to set the p_TRANSACTION_NUMBER passed in value to 60 before I call the stored procedure. This is a number.


(2) After I set the values in the Parameters … how do I execute the Stored Procedure .. like is done by hitting the execute button in the Visual Studio. I did not see .Execute property…

Sorry for such a newbie question .. however I am ...thanks in advance...

More info

Posted: Thu 07 Apr 2005 16:59
by pbright
Forgot to mention using OraDirect .NET 3.00 Beta version

Solution Was the Following:

Posted: Thu 07 Apr 2005 18:42
by pbright
This worked ...

OracleConnection Connection = new OracleConnection(ClearConnectionString);
Connection.Open();
OracleCommand Command = new OracleCommand();
Command.Connection = Connection; //connection to use
Command.CommandText = "CREATEORDER"; //stored procedure to call
Command.CommandType = System.Data.CommandType.StoredProcedure;

Command.Parameters.Add("P_TRANSACTION_NUMBER", OracleDbType.Number).Value = 600;

Command.ExecuteNonQuery();

Command.Dispose();
Connection.Close();