Error passing parameter to proc with dapper

-1

I have this 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 foreach iteration variable.

In my opinion everything is correct and I do not know why the error above.

    
asked by anonymous 03.04.2018 / 23:26

1 answer

0
Well, I do not use @ to pass the parameters but rather the: but you have to see your sql to understand even, but follow the 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 must be equal to sql, without more and without less.

    
03.04.2018 / 23:35