在按钮上单击Form1
,我将ID
传递给Form2
private void BTN_Print_Click(object sender, EventArgs e)
{
string P_ID = TB_ID.Text;
F0118 newForm = new F0118(P_ID);
newForm.ShowDialog();
}
来自Form2
上的form_load
,其中包含Report Viewer
,我正在传递参数,如下所示
public F0118(string P_ID)
{
InitializeComponent();
vID = P_ID;
}
onLoad事件
private void F0118_Load(object sender, EventArgs e)
{
string RepPath = Application.StartupPath + @"\REP0100.rpt";
ReportDocument rep = new ReportDocument();
rep.Load(RepPath);
rep.SetParameterValue("P_ID", Convert.ToInt32(vPatientID));
RepViewer.ReportSource = rep;
rep.Refresh();
}
问题是该报告似乎在运行时未获取参数,因为它总是提示您输入参数,如下图所示,当我输入一个id并按OK时,报告将正确运行
我错过了什么? 如何检查参数是否传递给报告?