我为用户创建了一个winform,以查看我为他们创建的许多报告。我有一个带有报告名称的下拉列表,它触发相应的字段以显示参数。一旦填写完毕,他们按提交并显示报告。这是他们第一次点击屏幕时的工作原理。他们可以更改参数,ReportViewer可以正常工作。更改为其他报告,我收到以下ReportViewer错误:
An error occurred during local report processing.
An error has occurred during the report processing.
A data source instance has not been supplied for the data source "CgTempData_BusMaintenance".
就我使用的流程而言:
reportName
(字符串)设置为物理RDLC名称。dataSource
(字符串)设置为DataSource名称LocalReport.ReportPath = "Reports\\" = reportName;
LocalReport.DataSources.Clear()
LocalReport.DataSources.Add(new ReportDataSource(dataSource, dt));
RefreshReport()
。以下是设置并显示ReportViewer的代码部分:
/// <summary>
/// Builds the report.
/// </summary>
private void BuildReport()
{
DataTable dt = null;
ReportingCG rcg = new ReportingCG();
if (reportName == "GasUsedReport.rdlc")
{
dataSource = "CgTempData_FuelLog";
CgTempData.FuelLogDataTable DtFuelLog = rcg.BuildFuelUsedTable(fromDate, toDate);
dt = DtFuelLog;
}
else if (reportName == "InventoryCost.rdlc")
{
CgTempData.InventoryUsedDataTable DtInventory;
dataSource = "CgTempData_InventoryUsed";
DtInventory = rcg.BuildInventoryUsedTable(fromDate, toDate);
dt = DtInventory;
}
else if (reportName == "VehicleMasterList.rdlc")
{
dataSource = "CgTempData_VehicleMaster";
CgTempData.VehicleMasterDataTable DtVehicleMaster = rcg.BuildVehicleMasterTable();
dt = DtVehicleMaster;
}
else if (reportName == "BusCosts.rdlc")
{
dataSource = "CgTempData_BusMaintenance";
dt = rcg.BuildBusCostsTable(fromDate, toDate);
}
// Setup the DataSource
this.reportViewer1.Visible = true;
this.reportViewer1.LocalReport.ReportPath = "Reports\\" + reportName;
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(dataSource, dt));
this.reportViewer1.RefreshReport();
}
如何删除所有旧的剩余数据?我是否处置了对象并重新创建它?
答案 0 :(得分:2)
我明白了。我需要在方法的开头添加:reportViewer1.Reset();
。