我有一个网络服务礼品兑换。兑换成功后,我想生成发票(pdf内容)并存储到数据库中。在调试时,当它处于renderedBytes进程时,它会提示“本地报告处理期间发生错误”。
rdlc位于Web服务文件夹中。 以下代码适用于Web应用程序,但不适用于Web服务。
Public dtInvDtl As New DataTable
Protected Function GenerateInvoice(ByVal sID As String) As Boolean
Dim dtInvoice As DataTable = (get record from database)
Dim dtInvoiceDtl = (get record from database)
dtInvDtl = dtInvoiceDtl
oLocalReport = New LocalReport
oLocalReport.ReportPath = HttpContext.Current.Server.MapPath("Invoice.rdlc")
Dim reportDataSource As ReportDataSource = New ReportDataSource("DS_INVOICE", dtInvoice)
oLocalReport.DataSources.Add(reportDataSource)
' Add handler for subreporting binding function
AddHandler oLocalReport.SubreportProcessing, AddressOf Subreport
Dim reportType As String = "PDF"
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim fileNameExtension As String = String.Empty
Dim deviceInfo As String = "<DeviceInfo>" & _
" <OutputFormat>PDF</OutputFormat>" & _
" <PageWidth>8.5in</PageWidth>" & _
" <PageHeight>11in</PageHeight>" & _
"</DeviceInfo>"
Dim warnings() As Warning = Nothing
Dim streams() As String = Nothing
Dim renderedBytes() As Byte
' Render the report
renderedBytes = oLocalReport.Render(reportType, deviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)
End Function
'SubReporting Binding Function
Protected Sub Subreport(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
e.DataSources.Clear()
Dim rds = New ReportDataSource("INVOICE_DTL", dtInvDtl)
e.DataSources.Add(rds)
End Sub