ExecuteArray Stored Procedure sample

ExecuteArray Stored Procedure sample

Postby susahin80 » Tue 23 Aug 2011 12:56

Hi,

Is there a sample using ExecuteArray with oracle Stored Procedure?
susahin80
 
Posts: 4
Joined: Tue 09 Aug 2011 15:57

Postby StanislavK » Wed 24 Aug 2011 13:26

The ExecuteArray method can be used to invoke a procedure in the same way it is used for simple SQL statements:
Code: Select all
// Create a command and set its type to 'StoredProcedure'.
OracleCommand cmd = new OracleCommand("insert_dept", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;

// Create command parameters.
cmd.Parameters.Add(new OracleParameter("p0", OracleDbType.Integer));
cmd.Parameters.Add(new OracleParameter("p1", OracleDbType.VarChar));

// Bind arrays as parameter values.
cmd.Parameters["p0"].Value = new int[] { 50, 60, 70 };
cmd.Parameters["p1"].Value = new string[] { "Dept50", "Dept60", "Dept70" };

// Execute the command.
cmd.ExecuteArray(3);

The database objects used in the sample are defined as
Code: Select all
CREATE PROCEDURE insert_dept (p0 IN NUMBER, p1 IN VARCHAR2)
AS
BEGIN
  INSERT INTO dept(deptno, dname) VALUES (p0, p1);
END;

CREATE TABLE dept (
  deptno NUMBER(4) CONSTRAINT PK_DEPT PRIMARY KEY,
  dname VARCHAR2(14) ,
  loc VARCHAR2(13)
);
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to dotConnect for Oracle