How to call a precedent using an oracle out-type course with C#

Asked

Viewed 76 times

1

I’m taking a test to figure out how to make a call from a trial that has this kind of course

inserir a descrição da imagem aqui

In the past I have this:

create or replace PROCEDURE                "PTESTE" 
(
pcd_servicoagendado integer,
ptipo integer, -- 0 principal, 1 debitos
p_cursor out pkgcursor.t_cursor
).....

In my project I have:

namespace Generico.Aplicacao
{
    public class AtualizaAplicacao
    {
        private Contexto contexto;

        public void TesteConsultaSql()
        {
            string servico = "30864";
            string tipo = "0";

            var strQuery = "";
            strQuery += " PTESTE";
            strQuery += string.Format(" @pcd_servicoagendado = '{0}' , ", servico);
            strQuery += string.Format(" @ptipo = '{0}' ", tipo);


            using (contexto = new Contexto())
            {
                var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
            }

        }


    }

}

my repository

    namespace Generico.Repositorio
    {
        public class Contexto : IDisposable
        {
            private readonly OracleConnection minhaConexao;

            public Contexto()
            {
                minhaConexao = new OracleConnection(ConfigurationManager.ConnectionStrings["Conexao"].ConnectionString);
                minhaConexao.Open();
            }

            public void ExecutaComando(string strQuery)
            {
                var cmdComando = new OracleCommand
                {
                    CommandText = strQuery,
                    CommandType = CommandType.Text,
                    Connection = minhaConexao
                };

                cmdComando.ExecuteNonQuery();
            }

            public OracleDataReader ExecutaComandoComRetorno(string strQuery)
            {
   var cmdComando = new OracleCommand(strQuery, minhaConexao);
        cmdComando.Parameters.Add("P_CURSOR", OracleType.Cursor).Direction = ParameterDirection.Output;
        return cmdComando.ExecuteReader();
            }

            public void Dispose()
            {
                if (minhaConexao.State == ConnectionState.Open)
                    minhaConexao.Close();
            }
        }
    }
  • if OracleDataReader implements IDataReader would just make a while (retornoDataReader.Read()) { //retornoDataReader["coluna"].ToString(); }, nay ?!

  • @Rovannlinhalis problem and error giving in return

  • which error ? I think command type has to be: cmd.CommandType = System.Data.CommandType.StoredProcedure; and not TEXT

  • @Rovannlinhalis, look at the picture, I improved the question

  • @Rovannlinhalis, the Procedure receives 2 parameters, but has a cursor type that needs to be passed,

  • tried: cmdComando.CommandType = System.Data.CommandType.StoredProcedure; ?

  • I get it, maybe it’s something more specific to the oracle, so I can’t help you

  • Try calling ExecuteNonQuery instead of ExecuteReader

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.