【问题标题】:Set a report datasource instance at run time在运行时设置报表数据源实例
【发布时间】:2013-10-08 09:38:46
【问题描述】:

我创建了一个基于业务对象的报告 - 这非常有效。我现在正在尝试添加一个将报告直接呈现为 PDF 的按钮(在 winforms 应用程序中)。 我知道我需要做什么 - 在代码中我正在创建一个ReportViewer,设置DataSource,指定报告(它是一个嵌入式资源),然后在使用System.IO.File.WriteAllBytes 刷新之前将报告呈现为字节数组字节数组到磁盘。我挂断的一件事是如何正确指定对象的实例?我不断收到“报告处理期间发生错误”错误。在IntelliTrace 中,我可以看到抛出异常“未为数据源'IssRep' 提供数据源实例”(IssRep 是报告中的数据集名称。代码如下:

Dim warning As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimetype As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing

Dim viewer As New ReportViewer
Dim bs As New BindingSource
bs.DataSource = issuedet
Dim rds As New ReportDataSource
rds.Value = bs


viewer.LocalReport.DataSources.Add(rds)
viewer.ProcessingMode = ProcessingMode.Local
viewer.LocalReport.ReportEmbeddedResource = "FRSFE.SR.rdlc"

Dim pdfbytes As Byte()
Try
    pdfbytes = viewer.LocalReport.Render("PDF", Nothing, mimetype, encoding, extension, streamids, warning)
    File.WriteAllBytes("C:\Shared\FRS\SR.PDF", pdfbytes)
Catch ex As Exception
    MsgBox(ex.Message)
End Try

我很确定我遇到的任何问题都很简单,因为我对 .NET 很生疏,但我就是想不通!

【问题讨论】:

    标签: vb.net binding reporting-services report


    【解决方案1】:

    在将rds.Name = "IssRep" 添加到viewer.LocalReport.DataSources 之前尝试设置它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 2014-02-07
      • 2017-10-22
      • 2016-10-01
      相关资源
      最近更新 更多