0

From the following code I get the error that @StartDate is not supplied, however stepping through the two date range parameters have a valid value:

SqlParameter[] ps = new SqlParameter[]
{
    new SqlParameter("@StartDate", startDate),
    new SqlParameter("@EndDate", endDate)
};

List<AttendanceReportViewModel> res = db.Database.SqlQuery<AttendanceReportViewModel>(Local.queries["AttendanceReport"], ps).ToList();

return res;

The stored procedure :

ALTER PROCEDURE [dbo].[GetAttendanceReport]
    @StartDate datetime,
    @EndDate datetime
AS
BEGIN
    SET NOCOUNT ON;

    exec [REMOTE_SRV].LWD.dbo.ReportAttendance_sp @StartDate = @StartDate, @EndDate = @EndDate;
END

Everything works fine when I execute the stored procedure in SQL Server Management Studio but doesn't from within the application.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Lee
  • 3,869
  • 12
  • 45
  • 65

1 Answers1

1

If your Local.queries["AttendanceReport"] looks something like this:

Local.queries["AttendanceReport"] = "yourProc @StartDate, @EndDate"

Then try this:

List<AttendanceReportViewModel> res = db.Database.SqlQuery<AttendanceReportViewModel(
    Local.queries["AttendanceReport"], 
    new SqlParameter("StartDate", startDate),
    new SqlParameter("EndDate", endDate)
).ToList();
Aaron Palmer
  • 8,912
  • 9
  • 48
  • 77