【发布时间】:2010-05-21 08:08:50
【问题描述】:
我有一个基于参数化存储过程的 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");
}
}
}
【问题讨论】:
标签: .net crystal-reports