1
I’m taking a test to figure out how to make a call from a trial that has this kind of course
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
implementsIDataReader
would just make awhile (retornoDataReader.Read()) { //retornoDataReader["coluna"].ToString(); }
, nay ?!– Rovann Linhalis
@Rovannlinhalis problem and error giving in return
– Harry
which error ? I think command type has to be:
cmd.CommandType = System.Data.CommandType.StoredProcedure;
and not TEXT– Rovann Linhalis
@Rovannlinhalis, look at the picture, I improved the question
– Harry
@Rovannlinhalis, the Procedure receives 2 parameters, but has a cursor type that needs to be passed,
– Harry
tried:
cmdComando.CommandType = System.Data.CommandType.StoredProcedure;
?– Rovann Linhalis
I get it, maybe it’s something more specific to the oracle, so I can’t help you
– Rovann Linhalis
Try calling
ExecuteNonQuery
instead ofExecuteReader
– Bruno Costa