Monday, August 17, 2009

Record retreiving C# using OracleProcedure

Oracle Proc:

create or replace procedure returnAllRecords(cur_allrec out t_cursor)
is
begin
open cur_allrec for SELECT * from Students;
end returnAllRecords


on Button click event write this below code:



OracleConnection Conn = new OracleConnection("Data Source=ORCL; User ID=scott; Password=tiger")
OracleCommand Cmd = new OracleCommand();
Cmd.Connection = Conn;
Cmd.CommandText = "returnAllRecords";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("cur_allrec", OracleType.Cursor).Direction = ParameterDirection.Output;
try

{

Conn.Open();

OracleDataReader Reader = Cmd.ExecuteReader();


}

catch (Exception ex)

{

Response.Write(ex.ToString();

}


Conn.Close();