1

Can someone please it explain this to me? I have this stored proc:

ALTER proc [dbo].[Invoice_GetHomePageInvoices] (
      @AreaIdList varchar(max)
,      @FinancialYearStartDate datetime = null
,      @FinancialYearEndDate datetime = null
) as

In code I'm trying to call it like this:

var areasString = new SqlParameter("AreaIdList", "1,2");
var startDate = new SqlParameter("FinancialYearStartDate", financialYear.StartDate);
var endDate = new SqlParameter("FinancialYearEndDate", financialYear.EndDate);

return _db.Database.SqlQuery<HomePageInvoice>("Invoice_GetHomePageInvoices", areasString, startDate, endDate);

I'm getting this error:

Procedure or function 'Invoice_GetHomePageInvoices' expects parameter '@AreaIdList', which was not supplied.

Say what? I've provided that parameter. Can someone please give me some insight into how to fix?

1
  • 1
    Have you tried putting the @ symbol in front of the variable name? Commented Apr 16, 2012 at 22:55

2 Answers 2

5

You need to call it like so:

var areasString = new SqlParameter("AreaIdList", "1,2");             
var startDate = new SqlParameter("FinancialYearStartDate", financialYear.StartDate);             
var endDate = new SqlParameter("FinancialYearEndDate", financialYear.EndDate);              
return _db.Database.SqlQuery<HomePageInvoice>("EXEC Invoice_GetHomePageInvoices @AreaIdList, @FinancialYearStartDate, @FinancialYearEndDate", areasString, startDate, endDate);

I believe you could shorten it up a bit too, like:

return _db.Database.SqlQuery<HomePageInvoice>("EXEC Invoice_GetHomePageInvoices {0}, {1}, {2}", "1,2", financialYear.StartDate, financialYear.EndDate);
Sign up to request clarification or add additional context in comments.

1 Comment

I could only get the shortened answer to work here. Nothing else seemed to function. Also, when specifying parameters, I had to specify them all, even if there were defaults within the stored procedure.
0

It's probably expecting the parameter values:

return _db.Database.SqlQuery<HomePageInvoice>("Invoice_GetHomePageInvoices", areasString.Value, startDate.Value, endDate.Value)

2 Comments

What would be the point of creating the parameters though if then you just pass the values. Doesn't work anyway.
You're right, I just thought you got the syntax mixed up. Are you using the DAAB here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.