Reputation: 55
I have a stored procedure defined in the database and I am trying to call it from the C# server.
In my repository I have a generic method that looks like this:
private IList<T> ExecuteReturningProcedure<T>(string procedureName, params ValueTuple<string, object>[] parameters)
{
List<T> objList = null;
ExecuteCommand(procedureName, parameters, CommandType.StoredProcedure, (cmd) =>
{
using (var reader = cmd.ExecuteReader())
{
objList = MapToList<T>(reader).ToList();
}
});
return objList;
}
and I made the specific method for my call that looks like this:
public List<dynamic> GetDataSubmissionEntries(Guid dataSubmissionId)
{
var parameters = Array.Empty<ValueTuple<string, object>>();
parameters.Append(new ValueTuple<string,object>("@dataSubmissionId", dataSubmissionId));
var entries = ExecuteReturningProcedure<dynamic>("[DataSubmission].[RetrieveDataSubmissionEntries]", parameters);
return entries.ToList();
}
The problem is that when the code is executed I get an exception with the message: Procedure or function 'RetrieveDataSubmissionEntries' expects parameter '@dataSubmissionId', which was not supplied.
Am I contructing the array of parameters the wrong way?
Upvotes: 1
Views: 298
Reputation: 308
Try setting the parameters for the SP like this:
SqlCommand cmd_Sp = new SqlCommand("YourSPname", conn);
cmd_Sp.CommandType = CommandType.StoredProcedure;
cmd_Sp.Parameters.Add("@dataSubmissionId", SqlDbType.VarChar).Value = dataSubmissionId.ToString();
Upvotes: 1