How to take the return of a trial to know if you had any lines affected?

Asked

Viewed 667 times

0

My question is whether there were any lines affected in the execution of this Procedure and store the result in a variable of type int.

If = 0, stop the process.

If > 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;
        }
    }

1 answer

1


There are two points to check:

1. To stored Procedure is returning the number of records affected?

You must perform the 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 yourself, for example, in SQL Server using the variable @@ROWCOUNT which returns the number of affected rows

2. Is treating the return?

In your code, the line that executes the Procedure that’s the one:
db.Executar(query, extrato) but I don’t see the return of that call, something like var total = db.Executar(query, extrato). If you do not treat the return this way, or with a parameter of output, even if the Procedure return you will not have that value.

Browser other questions tagged

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