我有一个水晶报告,我在其中以编程方式设置数据源和参数。当我只在报告中显示常规数据时,这很有效。但是,当我尝试在报告标题中显示参数值(它是一个日期)时,系统会提示我输入参数。关于造成这种情况的任何想法?我是水晶报告的新手,所以这可能是一个非常简单的问题。
这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace CrystalReportsTestApp
{
public partial class ReportForm : Form
{
ReportDocument report = new ReportDocument();
public ReportForm()
{
InitializeComponent();
}
private void ConfigureCrystalReports()
{
string reportPath = "mypath\\CrystalReport1.rpt";
report.Load(reportPath);
}
private void RunReportButton_Click(object sender, EventArgs e)
{
DateTime date = dateTimePicker1.Value;
DataSet reportData = new DataSet();
SqlConnection conn = null;
SqlDataAdapter da = null;
try
{
conn = new SqlConnection(connectionString);
conn.Open();
da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("cms.GetActiveEntityAccounts", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@EndDate", SqlDbType.DateTime).Value = date;
da.SelectCommand = cmd;
da.Fill(reportData, "DataTable1");
}
finally
{
if (conn != null)
{
conn.Close();
}
}
report.SetDataSource(reportData);
report.SetParameterValue("@EndDate", date);
crystalReportViewer1.ReportSource = report;
crystalReportViewer1.RefreshReport();
}
private void ReportForm_Load(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
}
}