我有一個基於參數化存儲過程的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");
}
}
}