【发布时间】:2013-04-05 13:18:24
【问题描述】:
我正在使用 MVC4 和实体框架来开发 Intranet Web 应用程序,其中一项要求是该应用程序将能够创建报告。所以我正在使用报告服务来做到这一点。
在我的报告文件 (.rdlc) 中,我有一个表,它应该包含我在“人员”表中的所有记录。我创建了一个存储过程,它从我的数据库中获取所有人员以及一个允许下载报告的操作。
问题是,我不知道如何告诉我的操作我的数据源是我的存储过程。
这是我的行动:
public ActionResult PersonReport()
{
ReportViewer personReportViewer = new ReportViewer();
List<ReportParameter> reportParameters = new List<ReportParameter>();
reportParameters.Add(new ReportParameter("Title", "Test"));
personReportViewer.LocalReport.SetParameters(reportParameters);
personReportViewer.ProcessingMode = ProcessingMode.Local;
personReportViewer.LocalReport.ReportEmbeddedResource =
HttpContext.Server.MapPath(".") + "\\Reporting\\Templates\\"
+ "PersonReport.rdlc";
byte[] byteArray = personReportViewer.LocalReport.Render("PDF");
Response.ClearHeaders();
Response.AddHeader("Content-Disposition",
"attachment; Filename=\"" + DateTime.Now + "_Title_" + "\"");
Response.AddHeader("Content-Transfer-Encoding", "Binary");
Response.BinaryWrite(byteArray);
Response.Flush();
Response.End();
return RedirectToAction("Index");
}
这是我的存储过程:
ALTER PROCEDURE dbo.GetAllPersons
AS
BEGIN
SET NOCOUNT ON
SELECT * FROM bm_Persons;
END
知道如何做到这一点吗?非常感谢。
【问题讨论】:
-
您能解释一下“告诉我的操作我的数据源是我的存储过程”吗?因为这对我来说毫无意义?
-
事实上,当我启动应用程序并单击与我的操作相关的链接时,它会返回一个错误,告诉我没有来源可以填充我的表格。
标签: c# sql asp.net-mvc stored-procedures reporting-services