2014-01-29 39 views
0

从下面的代码我得到@StartDate没有提供错误,但通过这两个日期范围参数步进参数有一个有效值:存储过程预计正在传递

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; 

存储过程:

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 

当我在SQL Server Management Studio中执行存储过程但不在应用程序内时,一切正常。

+0

什么是你referecing到参数的类型? – cubitouch

+0

这两个参数都是'DateTime' – Lee

+0

TSQL和.NET的观点? – cubitouch

回答

1

如果您Local.queries["AttendanceReport"]看起来是这样的:

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

那就试试这个:

List<AttendanceReportViewModel> res = db.Database.SqlQuery<AttendanceReportViewModel(
    Local.queries["AttendanceReport"], 
    new SqlParameter("StartDate", startDate), 
    new SqlParameter("EndDate", endDate) 
).ToList(); 
+0

这工作,谢谢。我也错过了我的参数之间的逗号。 – Lee