VB.Net Crystal Report数据源是一个具有一些NULL属性的.Net对象

时间:2013-10-15 20:46:03

标签: vb.net crystal-reports datasource

我正在尝试使用自定义对象作为数据源创建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

1 个答案:

答案 0 :(得分:0)

您没有使用DBNull,您正在使用Crystal不理解的Of Nullable。不确定他们什么时候会支持这个。请参阅此链接crystal-does-not-support-systemnullable