我有一个基于参数化存储过程的Crystal报表。该报告显示每个参数的值以及数据。在正常使用中,一切正常。将数据推送到Crystal报表时参数值未显示?
我现在需要添加一些额外的功能到我的报告应用程序,对存储过程返回的数据做一些额外的处理。为了达到这个目的,我想从我的C#代码中调用该过程,并将数据和参数值一起推送到报告中。
作为一个概念验证,我正在用虚拟数据构建一个数据表并将其推送到报告中。参数值不会出现在报告中,但会显示虚拟数据。我究竟做错了什么?
我使用Crystal Reports 11.5构建报表,并使用Visual Studio 2010构建应用程序。我使用的代码是:
using System;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace ReportTest
{
class Program
{
static void Main(string[] args)
{
var fakeTable = new DataTable("report_for_date;1");
fakeTable.Columns.Add("Name", typeof(string));
fakeTable.Columns.Add("Amount", typeof(decimal));
var row = fakeTable.NewRow();
row["Name"] = "TEST";
row["Amount"] = 1000;
fakeTable.Rows.Add(row);
var rep = new ReportDocument();
rep.Load("reportfordate.rpt", OpenReportMethod.OpenReportByDefault);
rep.SetDataSource(fakeTable);
rep.SetParameterValue("@date", new DateTime(2010, 05, 21));
rep.SetParameterValue("@threshold",5);
// This code prints out the expected values (set above)
foreach (ParameterField p in rep.ParameterFields)
foreach(ParameterDiscreteValue v in p.CurrentValues)
Console.WriteLine("{0}={1}", p.Name, v.Value);
// The report PDF is generated but does not display the parameter values
rep.ExportToDisk(ExportFormatType.PortableDocFormat,"c:/temp/hack.pdf");
}
}
}