Solved

c# parameter of type cursor

Posted on 2010-09-13
8
582 Views
Last Modified: 2012-05-10
Hi experts, i have this package in oracle
CREATE OR REPLACE PACKAGE pckCurso AS
      
  PROCEDURE upCursosHabilitadosPAPws(pCursor    OUT mGeneric);

as I call it from. net is considering a parameter of type cursor?

Can you help me modify this code? or have any better
public DataSet MostrarCursosHabilitadosPAP()
        {
            OracleConnection con;
            OracleCommand cmd;
            OracleDataAdapter adpt;
            DataSet ds = new DataSet();
            string SP = "pckCurso.upCursosHabilitadosPAPws";
            con = new OracleConnection(ConfigurationManager.ConnectionStrings["bdradesanewConnectionString"].ConnectionString);
            cmd = new OracleCommand(SP, con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@numdle", SqlDbType.NChar, 16).Value = numeroDocumento;
            adpt = new OracleDataAdapter(cmd);
            con.Open();
            adpt.Fill(ds);
            con.Close();
            return ds;
        }
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33667340

public DataSet MostrarCursosHabilitadosPAP()
        {
            OracleConnection con;
            OracleCommand cmd;
            OracleDataAdapter adpt;
            DataSet ds = new DataSet();
            string SP = "pckCurso.upCursosHabilitadosPAPws";
            con = new OracleConnection(ConfigurationManager.ConnectionStrings["bdradesanewConnectionString"].ConnectionString);
            cmd = new OracleCommand(SP, con);
            cmd.CommandType = CommandType.StoredProcedure;
OracleParameter[] parameters = new OracleParameter[2];
parameter[0] = new OracleParameter("@numdle", OracleType.NChar, 16);
parameter[0].Direction = ParameterDirection.Input;
parameter[0].Value = numeroDocumento;
parameter[1] = new OracleParameter("@numdle", OracleType.Cursor);
parameter[1].Direction = ParameterDirection.Output;            
cmd.Parameters.AddRange(parameters);
adpt = new OracleDataAdapter(cmd);
            con.Open();
            adpt.Fill(ds);
            con.Close();
            return ds;
        }
0
 

Author Comment

by:enrique_aeo
ID: 33667349
this is the code, it is work
public DataSet MostrarCursosHabilitadosPAP()
        {
            OracleConnection con;
            OracleCommand cmd;
            OracleDataAdapter adpt;
            DataSet ds = new DataSet();
            string SP = "pckCurso.upCursosHabilitadosPAPws";
            con = new OracleConnection(ConfigurationManager.ConnectionStrings["OracleDesa"].ConnectionString);

            try
            {
                cmd = new OracleCommand(SP, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("pCursor", OracleType.Cursor).Direction = ParameterDirection.Output;
                adpt = new OracleDataAdapter(cmd);
                con.Open();
                adpt.Fill(ds);
                con.Close();
                return ds;
            }
            catch (Exception ex)
            {
               
                throw ex;
            }
           
        }

can be improved using a finally???
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33667351
One more thing. You are trying to populate dataset. I hope you are NOT trying to populate the dataset with the output cursor.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:enrique_aeo
ID: 33667361
is exactly what I'm doing, I would not recommend?
0
 
LVL 16

Accepted Solution

by:
SriVaddadi earned 250 total points
ID: 33667368
public DataSet MostrarCursosHabilitadosPAP()
        {
            OracleConnection con;
            OracleCommand cmd;
            OracleDataAdapter adpt;
            DataSet ds = new DataSet();
            string SP = "pckCurso.upCursosHabilitadosPAPws";
            con = new OracleConnection(ConfigurationManager.ConnectionStrings["OracleDesa"].ConnectionString);

            try
            {
                cmd = new OracleCommand(SP, con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("pCursor", OracleType.Cursor).Direction = ParameterDirection.Output;
                adpt = new OracleDataAdapter(cmd);
                con.Open();
                adpt.Fill(ds);


            }
            catch (Exception ex)
            {
               
                throw ex;
            }
finally
{
adpt = null;
       cmd = null;
         if ((con != null) && (con.State != con.Closed))      
            con.Close();
      con = null;
}
                return ds;
           
        }
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 33667378
I was of a different understanding from your first snippet of code .. if your code works then its fine.
0
 

Author Comment

by:enrique_aeo
ID: 33667385
i have this error
Error 1 'System.Data.OracleClient.OracleConnection' does not contain a definition of 'Closed' or found no extension method 'Closed' accepting a first argument of type 'System.Data.OracleClient.OracleConnection' (missing a directive use or an assembly reference?) C: \ Users \ elopez \ Documents \ AMAG \ slnWSExcelInscritos \ wsConsultarInscripciones \ consultar.asmx.cs 54 56 wsConsultarInscripciones
0
 
LVL 16

Assisted Solution

by:SriVaddadi
SriVaddadi earned 250 total points
ID: 33667393
sorry, my bad
  if ((con != null) && (con.State != ConnectionState.Closed))      
            con.Close();
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question