I have a sequence in ORACLE that adds 1 to a row, as I show the current value when I open the APP

0

I need to show where the account is going so that when printing is shown and with this code sumo 1 to the consecutive

// contar 1 al consecutivo cuando imprima
        var oracleConnectionStringBuilder = new OracleConnectionStringBuilder
        {
            DataSource = _cnnString,
            UserID = _schema,
            Password = _pswSchema
        };

        OracleConnection con = new OracleConnection(oracleConnectionStringBuilder.ToString());
        OracleCommand oracommand = new OracleCommand("get_secuencia", con);
        oracommand.CommandType = CommandType.StoredProcedure;
        //OracleDataReader lector;
        try
        {
            con.Open();
            oracommand.Parameters.Add("consec", OracleDbType.Int32).Direction = ParameterDirection.Output;
            oracommand.ExecuteNonQuery();
            LNumDoc.Text = oracommand.Parameters["consec"].Value.ToString();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "xxxxx");
        }
        con.Close();

As I do to show the current value of the sequence, try CURRVAL but you can not use it without NEXTVAL that makes it add 1 to the sequence

    
asked by Saul Salazar 17.08.2018 в 23:40
source

1 answer

0

The sequences are not effective for the case of a consecutive in a bill it is best to use a stored procedure with a table that keeps the following as follows:

  • Create the table for the consecutive
  • then a stored procedure
  • then make the query
  • Procedure:

    create or replace PROCEDURE get_secuencia(consec OUT NUMBER)
    AS
    BEGIN
       UPDATE EQUIVALENTES_CONSECUTIVO SET CONSECUTIVO = CONSECUTIVO + 1;   
       SELECT CONSECUTIVO INTO consec FROM EQUIVALENTES_CONSECUTIVO;     
    END;
    

    Execution of the procedure

    var oracleConnectionStringBuilder = new OracleConnectionStringBuilder
            {
                DataSource = _cnnString,
                UserID = _schema,
                Password = _pswSchema
            };
    
            OracleConnection con = new OracleConnection(oracleConnectionStringBuilder.ToString());
            OracleCommand oracommand = new OracleCommand("get_secuencia", con);
            oracommand.CommandType = CommandType.StoredProcedure;
            //OracleDataReader lector;
            try
            {
                con.Open();
                oracommand.Parameters.Add("consec", OracleDbType.Int32).Direction = ParameterDirection.Output;
                oracommand.ExecuteNonQuery();
                LNumDoc.Text = oracommand.Parameters["consec"].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "xxxx");
            }
            con.Close();
    

    Show in a Label

    con.Open();
                consulta2 = "SELECT CONSECUTIVO FROM EQUIVALENTES_CONSECUTIVO";
                comando = new OracleCommand(consulta2, con);
                lector = comando.ExecuteReader();
                if (lector.Read())
                {
                    LNumDoc.Text = lector["CONSECUTIVO"].ToString();
                }
    con.Close();
    
        
    answered by 21.08.2018 / 19:21
    source