执行存储过程Oracle C#

时间:2014-12-01 16:49:13

标签: c# oracle stored-procedures oracle11g

我试图执行我在oracle DB上创建的过程,但由于它从未找到过程,我遇到了问题,我已经在这里按照oracle连接的文档进行了操作({{3但它并没有很好地运作。这是我的代码:

public static void ActualizarPacienteNn(Int64 idPacienteNN, Int64 idPaciente, string nombreUsuario, string contrasena)
{
    OracleConnection conexion = new OracleConnection();
    conexion = GenerarConexionOracle(nombreUsuario, contrasena);
    /*  
    OracleParameter[] parametros_procedimiento=new OracleParameter[]
    {
        new OracleParameter("ID_HCL_NN",idPacienteNN),
        new OracleParameter("ID_HCL_PACIENTE",idPaciente)
    };
    */

    OracleCommand comando = new OracleCommand();//se crea un comando
    comando.CommandType = System.Data.CommandType.StoredProcedure;
    comando.CommandText = "PROCEDURE";
    comando.Connection = conexion;
    comando.ParameterCheck = true;

    try
    {
        conexion.Open();
        OracleDataAdapter da = new OracleDataAdapter(comando);
        comando.ExecuteNonQuery();
    }

    catch (OracleException e)
    {
        Console.WriteLine(e);
        conexion.Close();

    }

    conexion.Close();
}

错误说,OBJECT"程序"不存在。 (而且我确信程序存在)。

我正在使用devart dotconnect和一个oracle DB 11g。谢谢。

1 个答案:

答案 0 :(得分:0)

根据文档

,您应该尝试这样的事情
public static void ActualizarPacienteNn(Int64 idPacienteNN, Int64 idPaciente, string nombreUsuario, string contrasena)
{
  //Establish connection
  OracleConnection conexion = new OracleConnection();
  conexion = GenerarConexionOracle(nombreUsuario, contrasena);

  conexion.Open();
  //Set up comando to reference stored procedure 'usp_ActualizaPaciente'
  OracleCommand comando = new OracleCommand("usp_ActualizaPaciente", myConn);
  comando.CommandType = System.Data.CommandType.StoredProcedure;
  comando.ParameterCheck = true;

  //Sample of how to bind parameters to the Stored Procedure
  OracleParameter myInParam1 = new OracleParameter();
  myInParam1.Value = idPaciente;
  myInParam1.ParameterName = "idPaciente";
  comando.Parameters.Add(myInParam1);
  myInParam1.Direction = System.Data.ParameterDirection.Input;

  //Execute the procedure.
  comando.ExecuteNonQuery();
  Console.WriteLine("Done");
  conexion.Close();
}

文档:http://www.devart.com/dotconnect/oracle/articles/parameters.html