Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Fill Dataset/DataReader (C#) from StoredProcedure??

520094Jan 13 2007 — edited Jan 15 2007
Dear ODP Friends,



I’ve used following Stored Procedure.
I’m using Dot Net(C#)I and want to Fill Dataset or Data reader.
Could some one be able to through the lights how to fill dataset or datareader from a storedprocedure.
Any idea would be valuable.

/*************************************************SQL,PL/SQL********************************************/
SQL> conn
Enter user-name: scott
Enter password: *****
Connected.
SQL> create or replace PROCEDURE Test
(
or_cursr out sys_refcursor
)
as
BEGIN
OPEN or_cursr FOR
SELECT * FROM Scott.Emp Where Empno=7788;
END Test;
/

Procedure created.

/**********************IN DOT NET(C#)*********************************/
Try
{
con.Open();
OracleCommand cmd = new OracleCommand("Test", con);
cmd.CommandType = CommandType.StoredProcedure;

DataSet ds = new DataSet();
OracleDataAdapter adptr=new OracleDataAdapter();
adptr.SelectCommand = cmd;
adptr.Fill(ds); //Here Error found.
MessageBox.Show(“Data set filled.”);
}
catch(OracleException ex){ MessageBox.Show(“Oracle Error\n”+ex.Message); }
catch (Exception ex) { MessageBox.Show(“General App Error”); }
finally
{
con.Close()
}

//**********************//
Error is :

Ora-06550: line 1, column 7:
PLS-00306: wrong Number or types of argument in call to ‘TESt’
Ora-06550: line 1, column 7:

Pl/Sql: statement ignored


Khurram

Comments

24208
Hi,

See the GetCursorFunction sample code in this OTN article:

http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_refcursors.html

Hope that helps,

Mark
520094
Yes..!!! hm hmm
Excelent. Its working fine.

Thanks a lot...William.
372016
You need to add a parameter to your command;

con.Open();
OracleCommand cmd = new OracleCommand("Test", con);
cmd.CommandType = CommandType.StoredProcedure;

OracleParameter pRet = cmCommand.Parameters.Add("r_cursor", OracleDbType.RefCursor );
pRet.Direction = ParameterDirection.Output;
OracleDataAdapter adptr=new OracleDataAdapter(cmd);
DataSet ds = new DataSet();
adptr.Fill(ds,"r_cursor");
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 12 2007
Added on Jan 13 2007
3 comments
1,465 views