views:

84

answers:

4

I Have a stored procedure:

CREATE OR REPLACE PROCEDURE UpdateFileMapping(field in number, original_Field_Names in DBMS_SQL.varChar2_table, mapped_Field_Ids in DBMS_SQL.number_table)
IS 
C NUMBER := DBMS_SQL.OPEN_CURSOR;
N NUMBER;
BEGIN
DBMS_SQL.PARSE(C,'INSERT INTO input_file_mapping VALUES(input_file_mapping_id.NextVal, 3, field, :fieldName, :mappedFieldId)', DBMS_SQL.NATIVE);

DBMS_SQL.BIND_ARRAY(C,':fieldName', original_Field_Names);
DBMS_SQL.BIND_ARRAY(C,':mappedFieldId', mapped_Field_Ids);
N := DBMS_SQL.EXECUTE(C);
DBMS_SQL.CLOSE_CURSOR(C);
END;

How to call such procedure which takes as input of DBMS_SQL.varChar2_table type from C#?

A: 

You need to include the proper ODP.NET provider for your system and then use OracleConnection and OracleCommand types to create a connection and execute the stored procedure. ODP.NET comes with extensive documentation and many examples.

Darin Dimitrov
Why don't just use `System.Data.OracleClient` ?
abatishchev
Because [it's deprecated](http://blogs.msdn.com/b/adonet/archive/2009/06/15/system-data-oracleclient-update.aspx).
Darin Dimitrov
@Darin: OMG. Thanks for info!
abatishchev
A: 

Try:

void ExecOracleStoredProcedure(int field, string[] original_Field_Names, int[] mapped_Field_Ids)
{
    using (OracleConnection connection = new OracleConnection(connectionString))
    using (OracleCommand command = connection.CreateCommand())
    {
        command.CommandText = "UpdateFileMapping";
        command.CommandType = CommandType.StoredProcedure;

        command.Parameters.AddWithValue(":field").Value = field;
        command.Parameters.AddWithValue(":original_Field_Names").Value = original_Field_Names;
        command.Parameters.AddWithValue(":mapped_Field_Ids").Value = mapped_Field_Ids;

        connection.Open();
        command.ExecuteNonQuery();
    }
}
abatishchev
it is throeing exception "wrong datatype or not sufficient argument";
Niraj Choubey
@Niraj: Try specify correct data types via `command.Parameters.Add()`
abatishchev
A: 

Looks like Enterprise Library from MS still support Oracle Database

For the Data Access Application Block, the following is also required:

A database server running a database that is supported by a .NET Framework 3.5 with Service Pack 1 or .NET Framework 4.0 data provider. This includes SQL Server® 2000 or later, SQL Server 2005 Compact Edition, and Oracle 9i or later. The database server can also run a database that is supported by the .NET Framework 3.5 with Service Pack 1 or the .NET Framework 4.0 data providers for OLE DB or ODBC.

adopilot
+1  A: 
create or replace procedure UpdateFileMapping(m in Number,y in    DBMS_SQL.varChar2_table,z in DBMS_SQL.number_table)
IS  
C NUMBER;
N NUMBER;

BEGIN

C := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(C,'INSERT INTO tablename VALUES(:x  ,:fieldName,:mappedFieldId)',DBMS_SQL.NATIVE);
 DBMS_SQL.BIND_ARRAY(C,':fieldName',original_Field_Names);
DBMS_SQL.BIND_ARRAY(C,':mappedFieldId',mapped_Field_Ids);
DBMS_SQL.BIND_VARIABLE(C,':x',file_Id);
N := DBMS_SQL.EXECUTE(C);
DBMS_SQL.CLOSE_CURSOR(C);

END;

For more information: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_sql.htm

Niraj Choubey