我正在尝试使用我的自定义对象作为数据源创建一个 Crystal Report。除非对象的某些属性具有空值,否则一切都很好。在这种情况下,我收到错误:
Error number: 5
Exception has been thrown by the target of an invocation.
(帮助不大!)
这是我的代码的副本,显示一个 CrystalReportViewer 正确填充了一个没有空值的对象,另一个 CrystalReportViewer 给出了一个带有空值的对象的错误。
感谢您的任何帮助/建议!
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim cryRpt As New ReportDocument
'Verify the path to the Crystal Report's .RPT file:
Dim strReportPath As String = CurDir() & "\..\..\" & "rpt_report.rpt"
If Not IO.File.Exists(strReportPath) Then
Throw (New Exception("Unable to locate report file:" & vbCrLf & strReportPath))
End If
cryRpt.Load(strReportPath)
Dim reportArray1(0) As cls_object
reportArray1(0) = New cls_object()
reportArray1(0).iNumber = 99
reportArray1(0).strString = "Hello"
cryRpt.SetDataSource(reportArray1)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
Dim reportArray2(0) As cls_object
reportArray2(0) = New cls_object()
'reportArray1(0).iNumber = 99 'this is commented out. this line is the only difference
reportArray1(0).strString = "Hello"
cryRpt.SetDataSource(reportArray2)
CrystalReportViewer2.ReportSource = cryRpt
CrystalReportViewer2.Refresh()
Catch ex As Exception
MsgBox("Error number: " & Err.Number & vbCrLf & Err.Description, MsgBoxStyle.Exclamation, Err.Source)
End Try
End Sub
End Class
Public Class cls_object
Protected _iNumber As Integer?
Protected _strString As String
Public Property iNumber() As Integer
Get
Return _iNumber
End Get
Set(ByVal value As Integer)
_iNumber = value
End Set
End Property
Public Property strString() As String
Get
Return _strString
End Get
Set(ByVal value As String)
_strString = value
End Set
End Property
Public Sub New()
End Sub
End Class