Solved

c# parameter of type cursor

Posted on 2010-09-13
8
598 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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