ReportParameter 中的空值处理
Null Value Handling in ReportParameter
因此,在此应用程序中,最终用户在一个表单中输入所需的 RMA 信息,然后可以选择将其加载到报告视图中并打印。因为这个数据库是多年前放在一起的,所以空值位于 [Area Of Repair] 列中。我需要的是弄清楚如果检测到空值,如何将 "area" 的参数值设置为 "unknown"。以下是当前使用的方法的代码。
public void GenerateServiceReport(string[] RMArray, string TempDataset, DataTable Results)
{
serviceReportViewer.LocalReport.ReportPath = "D:\vsprojects\projects\emsdashboard\emsdashboard\RMAServiceReport.rdlc";
ReportParameter dateReceived = new ReportParameter("DateParameter", RMArray[0]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { dateReceived });
ReportParameter rmaNumber = new ReportParameter("RMAParameter", RMArray[1]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { rmaNumber });
ReportParameter workOrder = new ReportParameter("WorkOrderParameter", RMArray[2]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { workOrder });
ReportParameter qty = new ReportParameter("qtyParameter", RMArray[3]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { qty });
ReportParameter company = new ReportParameter("CompanyParameter", RMArray[4]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { company });
ReportParameter customer = new ReportParameter("CustomerParameter", RMArray[5]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { customer });
ReportParameter ecn = new ReportParameter("ecnParameter", RMArray[6]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { ecn });
ReportParameter warranty = new ReportParameter("WarrantyParameter", RMArray[7]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { warranty });
ReportParameter action = new ReportParameter("ActionParameter", RMArray[8]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { action });
ReportParameter part = new ReportParameter("PartParameter", RMArray[9]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { part });
ReportParameter area = new ReportParameter("AreaParameter", RMArray[10]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { area });
serviceReportViewer.LocalReport.DataSources.Clear();
serviceReportViewer.LocalReport.DataSources.Add(new ReportDataSource(TempDataset, Results));
serviceReportViewer.RefreshReport();
}
private void RMAServiceReport_Load(object sender, EventArgs e)
{
this.serviceReportViewer.RefreshReport();
this.serviceReportViewer.RefreshReport();
this.serviceReportViewer.RefreshReport();
}
像这样更改声明 area
变量行
ReportParameter area = new ReportParameter("AreaParameter", RMArray[10] ?? "unknown");
因此,在此应用程序中,最终用户在一个表单中输入所需的 RMA 信息,然后可以选择将其加载到报告视图中并打印。因为这个数据库是多年前放在一起的,所以空值位于 [Area Of Repair] 列中。我需要的是弄清楚如果检测到空值,如何将 "area" 的参数值设置为 "unknown"。以下是当前使用的方法的代码。
public void GenerateServiceReport(string[] RMArray, string TempDataset, DataTable Results)
{
serviceReportViewer.LocalReport.ReportPath = "D:\vsprojects\projects\emsdashboard\emsdashboard\RMAServiceReport.rdlc";
ReportParameter dateReceived = new ReportParameter("DateParameter", RMArray[0]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { dateReceived });
ReportParameter rmaNumber = new ReportParameter("RMAParameter", RMArray[1]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { rmaNumber });
ReportParameter workOrder = new ReportParameter("WorkOrderParameter", RMArray[2]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { workOrder });
ReportParameter qty = new ReportParameter("qtyParameter", RMArray[3]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { qty });
ReportParameter company = new ReportParameter("CompanyParameter", RMArray[4]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { company });
ReportParameter customer = new ReportParameter("CustomerParameter", RMArray[5]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { customer });
ReportParameter ecn = new ReportParameter("ecnParameter", RMArray[6]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { ecn });
ReportParameter warranty = new ReportParameter("WarrantyParameter", RMArray[7]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { warranty });
ReportParameter action = new ReportParameter("ActionParameter", RMArray[8]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { action });
ReportParameter part = new ReportParameter("PartParameter", RMArray[9]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { part });
ReportParameter area = new ReportParameter("AreaParameter", RMArray[10]);
serviceReportViewer.LocalReport.SetParameters(new ReportParameter[] { area });
serviceReportViewer.LocalReport.DataSources.Clear();
serviceReportViewer.LocalReport.DataSources.Add(new ReportDataSource(TempDataset, Results));
serviceReportViewer.RefreshReport();
}
private void RMAServiceReport_Load(object sender, EventArgs e) {
this.serviceReportViewer.RefreshReport();
this.serviceReportViewer.RefreshReport();
this.serviceReportViewer.RefreshReport();
}
像这样更改声明 area
变量行
ReportParameter area = new ReportParameter("AreaParameter", RMArray[10] ?? "unknown");