Issues calling Oracle stored procedure from C# -


this first time have ever had call oracle stored procedure c# , don't know why code not working. trying return datatable. stored procedure compiles fine - here pseudocode describing it:

create or replace procedure sproc_online ( year in number default null , name in varchar2 default null , id in varchar2 default null , refcursor out sys_refcursor ) begin open refcursor select * table field_year = year   , field_name = name   , field_id = id;   end sproc_online; 

here pseudocode describing c#:

public static datatable search(int? year, string name, string id)     {                     try         {             oracleconnection conn = getconnectionstring();                             oraclecommand cmd = new oraclecommand();             cmd.connection = conn;             cmd.commandtext = "sproc_online";             cmd.commandtype = commandtype.storedprocedure;             cmd.parameters.add("year", oracledbtype.int32).value = year;             cmd.parameters.add("name", oracledbtype.varchar2).value = name;             cmd.parameters.add("id", oracledbtype.varchar2).value = id;                             cmd.parameters.add("output", oracledbtype.refcursor).direction = parameterdirection.output;              datatable dt = new datatable();             oracledataadapter da = new oracledataadapter(cmd);             getconnectionstring().open();             cmd.executenonquery();             da.fill(dt);              return dt;                         }         catch (exception e) { throw new exception("error: " + e.message); }         { getconnectionstring().close(); }     } 

no errors being thrown; it's datatable returned null when should not (the parameters testing should returning something).

what doing wrong here?

i think may need use oracledatareader.

using(oraclecommand cmd = new oraclecommand("sproc_online", theconnection)) {     using(oracledatareader reader = new oracledatareader())     {         while(reader.read())         {             // extract values             var = reader["year"];             var b = reader["name"];             var c = reader["id"];             ... etc ...         }     } } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -