Error passing parameter to proc with Dapper

Asked

Viewed 340 times

-1

I got it inside a foreach:

parameter.Add("@PROD", item.CDProduto);
parameter.Add("@Filial", item.filial);
parameter.Add("@Cod_Oper", cod_oper);

var result = _connection.ExecuteReader("sp_InsereVenda", parameter, transaction, commandType: System.Data.CommandType.StoredProcedure);

when I run I get this error

System.Data.Sqlclient.Sqlexception (0x80131904): Procedure or Function 'sp_InsereVenda' expects Parameter '@PROD', which was not supplied.

item is the iteration variable of foreach.

In my view everything is correct and I do not know why the above mistake.

1 answer

0

All right, I don’t use @ to pass the parameters but :, but you have to see your sql to understand it, but here is an example below:

                #region Sql
            var sql = @" INSERT INTO FIS_GERENCIADOCTOFISCAL (NUMGUID,
                                                    DATMOVIMENTO,
                                                    NUMSEQUENCIAL,
                                                    LOJA,
                                                    NUMTERMINAL,
                                                    NUMORCAMENTO,
                                                    FLGSTATUS,
                                                    FLGOPERACAO,
                                                    DSCRETORNO
                                                   )
                                                VALUES (:NumGuid,
                                                    :DatMovimento,
                                                    :NumSequencial,
                                                    :Loja,
                                                    :CodTerminal,
                                                    :NumOrcamento,
                                                    :FlgStatus,
                                                    :FlgOperacao,
                                                    :DscRetorno
                                                   )";
            #endregion

            #region Parâmetros
            var parameters = new 
            {
                NumGuid = model.NumGuid,
                DatMovimento = model.DatMovimento,
                CodTerminal = model.NumTerminal,
                Loja = model.Loja,
                FlgStatus = model.FlgStatus,
                FlgOperacao = model.FlgOperacao,
                NumOrcamento = model.NumOrcamento,
                NumSequencial = sequence,
                DscRetorno = ""
            };
            #endregion

            return await _dbManager.ExecuteAsync(sql, parameters);

The name of the parameters has to be equal to sql, without more and without less.

  • Matheus, I use Dapper for that. That’s the question.

  • You have to put sql here too?

Browser other questions tagged

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