January 20, 2012

Using a DataReader Against an Oracle Stored Procedure

Following code snippet uses the DataReader object to retrieve data from an Oracle stored procedure. You can use the DataReader to retrieve a read-only, forward-only stream of data from a database.

Using the DataReader can increase application performance and reduce system overhead because only one row is ever in memory.

using(OracleConnection conn = new OracleConnection
(@"DataSource=source;User Id=username;Password=password;"))
          OracleCommand cmd = new OracleCommand();
          cmd.Connection = conn;
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "StoredProcedureName";
          cmd.Parameters.Add("Result",OracleType.Cursor).Direction =
          OracleDataReader dataReader = cmd.ExecuteReader();
          while(dataReader .Read())
                // do your logic here

No comments:

Post a Comment