您好我只是想在VB.NET中进行报道。
报表视图预览工作正常,因此它似乎不是报表本身的问题,但渲染为pdf表示“在本地报表处理期间发生错误”,内部异常表示“报表处理期间出错” “
我显然错过了一些但却看不到的东西。 如果有人能帮助解决这个问题,请不胜感激。
Private Sub ExportToPDFToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportToPDFToolStripMenuItem1.Click
Try
Dim viewer As New Microsoft.Reporting.WinForms.ReportViewer
Dim report = New Microsoft.Reporting.WinForms.LocalReport
viewer.LocalReport.ReportEmbeddedResource = "ECUWMS.10day.rdlc"
viewer.ProcessingMode = ProcessingMode.Local
Dim rpJob As New ReportParameter
rpJob.Name = "JobNo"
rpJob.Values.Add("0000030")
viewer.LocalReport.SetParameters(New ReportParameter() {rpJob})
viewer.RefreshReport()
Dim reportinfo As Byte() = viewer.LocalReport.Render("PDF") ' --> Errors here.
Dim SFD As New SaveFileDialog
SFD.Filter = "PDF Files(*.PDF) | *.pdf"
If SFD.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim newfile As New FileStream(SFD.FileName, FileMode.Create, FileAccess.Write)
newfile.Write(reportinfo, 0, reportinfo.Length)
newfile.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
End Try
End Sub
答案 0 :(得分:1)
根据ex.InnerException.InnerException.Message
中的“建议”,您需要向ReportDataSource
提供名为dsJobs
的{{3}}。
答案 1 :(得分:0)
感谢您的帮助。我认为这很接近完成,我也喜欢能够将过滤移动到数据集而不是报告的想法。 沙箱的东西似乎是一个陷阱。没有清除此VS会抛出异常。 只需更改sfd和输出,此逻辑也适用于Excel和Word。
这是一些代码,如果它可以帮助某人
Private Sub ExportToPDFToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportToPDFToolStripMenuItem1.Click
Dim viewer As New Microsoft.Reporting.WinForms.ReportViewer
Dim report = New Microsoft.Reporting.WinForms.LocalReport
Try
Me.Tblsop_hTableAdapter.Fill(Me.SqlecuDataSet.tblsop_h)
viewer.LocalReport.ReportEmbeddedResource = "ECUWMS.10day.rdlc"
viewer.ProcessingMode = ProcessingMode.Local
viewer.LocalReport.Refresh()
Dim dsJobs As New sqlecuDataSet
Dim ta As sqlecuDataSetTableAdapters.tblsop_hTableAdapter = Tblsop_hTableAdapter
ta.Fill(dsJobs.tblsop_h)
Dim repData As New ReportDataSource
repData.Name = "dsjobs"
repData.Value = dsJobs.tblsop_h
viewer.LocalReport.DataSources.Clear()
viewer.LocalReport.DataSources.Add(repData)
Dim rpJob As New ReportParameter
rpJob.Name = "JobNo"
rpJob.Values.Add("0000030")
viewer.LocalReport.SetParameters(New ReportParameter() {rpJob})
viewer.RefreshReport()
Dim reportinfo As Byte() = viewer.LocalReport.Render("PDF")
Dim SFD As New SaveFileDialog
SFD.Filter = "PDF Files(*.PDF) | *.pdf"
If SFD.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim newfile As New FileStream(SFD.FileName, FileMode.Create, FileAccess.Write)
newfile.Write(reportinfo, 0, reportinfo.Length)
newfile.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK)
MessageBox.Show(ex.InnerException.Message, "Error", MessageBoxButtons.OK)
MessageBox.Show(ex.InnerException.InnerException.Message, "Error", MessageBoxButtons.OK)
End Try
Viewer.LocalReport.ReleaseSandboxAppDomain()
End Sub