您好所有我有方法,其中i傳遞一些參數到存儲過程,當我執行它我得到這個錯誤在我的MVC3中執行存儲過程時發生錯誤?
[從物化「System.Int32」類型指定的強制轉換到「System.String」類型無效。]
我這是怎麼叫我的StoredProcedure
public JsonResult CreatedBugs()
{
int year;
int month;
int projectid;
year = 2012;
month = 8;
projectid = 16;
var loggedbugs = db.ExecuteStoreQuery<LoggedBugs>("LoggedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year",year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
var ClosedBugs = db.ExecuteStoreQuery<LoggedBugs>("ClosedBugs @Year,@Month,@ProjectID", new SqlParameter("@Year", year), new SqlParameter("@Month", month), new SqlParameter("@ProjectID", projectid)).ToList();
var model = new LoggedBugs
{
LoggedBugsCount = loggedbugs,
ClosedBugs = ClosedBugs
};
return Json(model, JsonRequestBehavior.AllowGet);
}
,這是我的StoredProcedure
alter procedure LoggedBugs
(
@Year int,
@Month int,
@ProjectID int
)
as
begin
SELECT projectName,
ProjectYear,
ProjectMonth,
Week1, Week2, Week3, Week4, Week5
FROM (
Select p.projectName,YEAR(b.CreatedDate) ProjectYear, MONTH(b.CreatedDate) ProjectMonth,
'Week' + CAST(DATEDIFF(week, DATEADD(MONTH, DATEDIFF(MONTH, 0, b.CreatedDate), 0), b.CreatedDate)+1 AS VARCHAR) as [Weeks],
b.BUGID
From BUGS b inner join projects p on b.ProjectId = p.ProjectId
Where DatePart(year, CreatedDate) = @Year and datepart(month, Createddate) = @Month and b.projectid = @ProjectID
) p
PIVOT (COUNT(BUGID) FOR [Weeks] IN (WEEK1, WEEK2, WEEK3, Week4, Week5)) AS pvt
end
我在哪裏做錯了
EDIT1
這裏是我的LoggedBug類
public class LoggedBugs
{
public string projectName { get; set; }
public string ProjectYear { get; set; }
public string ProjectMonth { get; set; }
public string Week1 { get; set; }
public string Week2 { get; set; }
public string Week3 { get; set; }
public string Week4 { get; set; }
public string Week5 { get; set; }
public IEnumerable<LoggedBugs> LoggedBugsCount { get; set; }
public IEnumerable<LoggedBugs> ClosedBugs { get; set; }
}
您可以顯示LoggedBugs類代碼,也都有哪些SQL類型ProjectYear,ProjectMonth,Week1,Week2,Week4,Week4,Week5。我的猜測是,你的proc返回一個int,但LoggedBugs有它定義爲一個字符串類型 – nuhusky2003
@ nuhusky2003我已經更新了我的問題與LoggedBug類,我投爲VARCHAR的ProjectYear,ProjectMonth,Week1,Week2,Week4,Week4 ,第5周 – SoftwareNerd