DAAB: The number of parameters does not match number of values for stored procedure

Topics: Data Access Application Block
Mar 29, 2011 at 3:36 PM
The call to ExecuteSprocAccessor is throwing an exception message "The number of parameters does not match number of values for stored procedure". Please advise.
Following is the extract of the code :


   //Entity Class
    public class Lookup
        private int _id;
        private string _domain;
        private string _name;
        private string _value;

        public int Id
            get { return _id; }
            set { _id = value; }
        public string Domain
            get { return _domain; }
            set { _domain = value; }
        public string Name
            get { return _name; }
            set { _name = value; }
        public string Value
            get { return _value; }
            set { _value = value; }
    //Parameter Mapper class
    public class LookupParameterMapper : IParameterMapper {

        public void AssignParameters(DbCommand command, object[] parameterValues)
            DbParameter DbParam = command.CreateParameter();
            DbParam.ParameterName = "Domain";
            DbParam.Value = parameterValues[0];

    //Data row mapper class
    class LookupMapper : IRowMapper<Lookup>, IResultSetMapper<Lookup>
        public Lookup MapRow(IDataRecord row)
            return new Lookup()
                Id = row.IsDBNull(row.GetOrdinal("ID")) ? Int32.MinValue : row.GetInt32(row.GetOrdinal("ID")),
                Domain = row.IsDBNull(row.GetOrdinal("Domain")) ? null : row.GetString(row.GetOrdinal("Domain")),
                Name = row.IsDBNull(row.GetOrdinal("Name")) ? null : row.GetString(row.GetOrdinal("Name")),
                Value = row.IsDBNull(row.GetOrdinal("Value")) ? null : row.GetString(row.GetOrdinal("Value"))

        public IEnumerable<Lookup> MapSet(IDataReader reader)
            List<Lookup> LookupList = null;
            while (reader.Read())
                IDataRecord Row = reader;
            return LookupList;
//Following is the code that makes the call to the stored procedure by passing the parameter value as "APPLICATION"
IParameterMapper ParamMapper = new LookupParameterMapper();
IRowMapper<Lookup> RowMapper = new LookupMapper();
IEnumerable<Lookup> results = ReportingDB.ExecuteSprocAccessor<Lookup>("usp_Lookup_sel2", RowMapper, ParamMapper, "APPLICATION");


--Below is the stored procedure 
CREATE PROCEDURE dbo.usp_Lookup_sel2
		@Domain			VARCHAR(50) = NULL
select ID,
from dbo.tblLookup AS l
where @Domain IS NULL OR l.Domain = @Domain



Mar 30, 2011 at 1:32 AM
Edited Mar 30, 2011 at 1:33 AM


You interchanged the RowMapper and ParameterMapper in your ExecuteSprocAccesor method. The corrected line of code will look like this:

IEnumerable<Lookup> results = ReportingDB.ExecuteSprocAccessor<Lookup>("usp_Lookup_sel2", ParamMapper, RowMapper, "APPLICATION");



Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.

Mar 30, 2011 at 10:29 AM

Thank you.  It works now.

Have another problem now.  How do I access the Stored Procedure OUTPUT parameters (and/or RETURN values) using the Accessor methods ?  Not able to find any documentation on this.  

Mar 31, 2011 at 1:41 AM

Currently, this isn't supported.  You could probably create an extension method which allows you to pass a DbCommand object so you could later retrieve the parameter vales.

I suggest you log this in the Issue Tracker as a feature request, I've already seen some people asking for the same functionality. 

By the way, please create a new discussion thread for each different concern/issue.


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.