Parameter for Stored Procedure not identified

Asked

Viewed 190 times

5

I’m having a problem, which would be a mistake saying that there is no parameter being passed to the Procedure.

It is running the following code:

cmdProcedure.Parameters.AddWithValue("@id", 0);

Command:

public List<Models.Admin> UpdateList()
{
    using (var context = new DbContext())
    {
        var cmdProcedure = new SqlCommand("GetAdmin");
        cmdProcedure.Parameters.AddWithValue("@id", 0);

        using (var data = context.ExecuteSelectProcedure(cmdProcedure))
        {
            return GetList(data);
        }
    }
}

public SqlDataReader ExecuteSelectProcedure(SqlCommand cmdProcedure)
{
    cmdProcedure.Connection = _connection;
    return cmdProcedure.ExecuteReader();
}

Here is my trial:

PROCEDURE [dbo].[GetAdmin]      
(
    @id int
)
AS
    BEGIN
        SET NOCOUNT ON;

        if (@id > 0)    
            SELECT * FROM Admin WHERE idAdmin = @id
        else
            SELECT * FROM Admin
    END

Error image: Erro

1 answer

3


Fixed issue! Just after completion of adding parameters the following line was missing:

cmdProcedure.CommandType = CommandType.StoredProcedure;

problem solved.

  • 1

    Luiz, please accept your answer as correct so the question is not pending. Hug!

  • It’s only 9:00 so I can still do this hehe.

  • Sorry, I forgot this =P

Browser other questions tagged

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