0
votes

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.

1
What is the type of the parameter you are referecing to ? - cubitouch
Both params are DateTime - Lee
Both TSQL and .NET point of view ? - cubitouch
Yes, I'll post the proof. - Lee

1 Answers

1
votes

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();