我正在使用以下代码更改按钮点击事件中报表查看器控件中显示的报表。
private void ReinitializeViewer(string tsReport)
{
ReportDataSource ReportDataSourceX = new ReportDataSource();
this.PurchaseReprotViewer.Reset();
this.PurchaseReprotViewer.LocalReport.ReportEmbeddedResource = tsReport;
if (tsReport.Contains("Rpt_PurchaseInvoice.rdlc"))
{
this.purchaseTableAdapter.Fill(this.gmsDataSet.purchase);
ReportDataSourceX.Name = "PurchaseInvoiceDataSet";
ReportDataSourceX.Value = this.gmsDataSet.Tables["purchase"];
}
else
{
ReportDataSourceX.Name = "DataSet1";
// ReportDataSourceX.Value = Me.MyBindingSource1
}
this.PurchaseReprotViewer.LocalReport.DataSources.Add(ReportDataSourceX);
//this.purchaseTableAdapter.Fill(this.gmsDataSet.purchase);
this.PurchaseReprotViewer.RefreshReport();
}
private void Cmd_PurchaseInvoices_Click(object sender, EventArgs e)
{
ReinitializeViewer("Rpt_PurchaseInvoice.rdlc");
}
但是我在输出中遇到了一个奇怪的错误。
我无法确定上述代码中出现的问题。 任何帮助表示赞赏。提前谢谢。
答案 0 :(得分:0)
自己找到答案。
以下代码为我工作:
private void ReinitializeViewer(string tsReport)
{
ReportDataSource ReportDataSourceX = new ReportDataSource();
this.PurchaseReprotViewer.Reset();
if (tsReport.Contains("Rpt_PurchaseInvoice.rdlc"))
{
ReportDataSourceX.Name = "PurchaseInvoiceDataSet";
ReportDataSourceX.Value = this.purchaseBindingSource;
this.PurchaseReprotViewer.LocalReport.DataSources.Add(ReportDataSourceX);
this.PurchaseReprotViewer.LocalReport.ReportEmbeddedResource = tsReport;
this.PurchaseReprotViewer.RefreshReport();
}
}