Parameter for unidentified Stored Procedure

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 procedure:

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:

    
asked by anonymous 18.02.2014 / 18:10

1 answer

3

Fixed problem! Soon after the completion of the parameter addition, the following line was missing:

cmdProcedure.CommandType = CommandType.StoredProcedure;

problem solved.

    
18.02.2014 / 18:34