How do I get a procedure return to see if it has any affected row?

0

My question is whether you had any affected strings in executing this procedure and store the result in a variable of type int .

If it is = 0 , stop the process.

If it is > 0 , proceed with the process.

I have the following codes:

Controller:

   public void InserirSaldoBonusExtrato(PCINET.pciPedidos.PedidoVenda pedido)
        {
            try
            {
                Extrato extrato = new Extrato(config);
                extrato.Cliente = pedido.PedCliente;
                extrato.Valor = pedido.PedValor;
                extrato.Ciclo = pedido.PedCiclo;
                extrato.TpOperCodigo = 9;
                extrato.TpOperNome = "Pgtopedido";
                extrato.Descricao = "Pagamento do pedido " + pedido.PedNumero + " com bônus";
                extrato.Indicante = 0;
                extrato.Pendente = "N";
                extrato.InserirSaldoBonusExtrato();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

Model:

 public void InserirSaldoBonusExtrato()
    {
        try
        {
            new ExtratoDB(config).InserirSaldoBonus(this);
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

Dapper (date):

   public void InserirSaldoBonus(Extrato extrato)
    {

        try
        {
            var db = new Data<Extrato>(config);
            string query = @"sp_InsereSaldoBonusExtrato @Cliente, @Valor, @Ciclo, @TpOperCodigo, @TpOperNome, @Descricao, @Indicante, @Pendente";
            db.Executar(query, extrato);

        }
        catch (Exception ex)
        {

            throw ex;
        }
    }
    
asked by anonymous 23.04.2018 / 18:08

1 answer

1

There are two points to check:

1 . Is the stored procedure returning the number of affected records?

You should run procedure and make sure it returns the number of affected records. For example, in SQL Server , must be set SET NOCOUNT OFF to execute the procedure , otherwise it is not returned. You can also return the value by itself, such as SQL Server using the @@ROWCOUNT variable that returns the number of rows affected

2 . Are you trying to return?

In your code, the line that runs procedure is this:
db.Executar(query, extrato) but I do not see the return of this call, something like var total = db.Executar(query, extrato) . If you do not treat the return like that, or with an output parameter, even if procedure returns you will not get this value.     

23.04.2018 / 18:33