0
我已經創建了一個基於業務對象的報表 - 這很好用。我現在試圖添加一個按鈕,將報表直接呈現爲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上很生疏,但我不能看着辦吧!