【问题标题】:VB.Net Crystal Report datasource is a .Net Object with some NULL propertiesVB.Net Crystal Report 数据源是一个具有一些 NULL 属性的 .Net 对象
【发布时间】:2013-10-23 19:38:41
【问题描述】:

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

【问题讨论】:

    标签: vb.net crystal-reports datasource


    【解决方案1】:

    您没有使用 DBNull,您使用的是 Of Nullable,Crystal 无法理解。不知道他们什么时候会支持这个。看这个链接crystal-does-not-support-systemnullable

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-08
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多