如何在Crystal Reports中使用带参数的存储过程?我在VS 2013,asp.net,MVC和razor中使用以下代码。
public ActionResult AllCustomerReports()
{
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("\\Reports\\rpt_AllCustomers.rpt"));
rd.SetDataSource(db.CUSTOMERs.Select(p => new
{
Id = p.Id,
CUSTOMER_CODE = p.CUSTOMER_CODE,
CUSTOMER_NAME = p.CUSTOMER_NAME,
CUSTOMER_EMAIL_ADDRESS = p.CUSTOMER_EMAIL_ADDRESS,
CUSTOMER_LANDLINE = p.CUSTOMER_LANDLINE,
CUSTOMER_TYPE_ID = p.CUSTOMER_TYPE.Id,
CUSTOMER_TYPE_NAME = p.CUSTOMER_TYPE.CUSTOMER_TYPE_NAME,
LOCATION_TYPE_ID = p.LOCATION_TYPE.Id,
LOCATION_TYPE_NAME = p.LOCATION_TYPE.LOCATION_TYPE_NAME,
INDUSTRY_TYPE_ID = p.INDUSTRY_TYPE.Id,
INDUSTRY_TYPE_NAME = p.INDUSTRY_TYPE.INDUSTRY_TYPE_NAME
}).ToList());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "ListofAllCustomers.pdf");
}
答案 0 :(得分:0)
您必须先在数据集或数据表中获取数据库记录,然后将该数据分配给报告,如下所示。 无需在报告中传递参数即可获取数据。您可以在sp direct 中传递这些参数。
DataSet ds = get data from database which call sp with parameter;
string reportPath = Server.MapPath("~/Reports/XXXXX.rpt");
reportDocument.Load(reportPath);
DataTable dt = ds.Tables[0].Copy();
reportDocument.SetDataSource(dt);
CrystalReportViewer.ReportSource = reportDocument;
CrystalReportViewer.DataBind();