Crystal Report无法加载

时间:2017-04-23 10:23:09

标签: vb.net crystal-reports

我的Crystal报表无法加载。

这是我的代码:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class bincard
    Private Sub bincard_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs)
        Dim cryRpt As New ReportDocument

        cryRpt.Load(Application.StartupPath + "bincard1.rpt")

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterFieldDefinitions =
            cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition =
            crParameterFieldDefinitions.Item("itemid")
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
    End Sub
End Class

3 个答案:

答案 0 :(得分:0)

自:

var dt = DateTime.ParseExact(startTime.Substring(0,19), 
                              "yyyy-MM-ddTHH:mm:ss", 
                              CultureInfo.InvariantCulture);

要:

cryRpt.Load(Application.StartupPath + "bincard1.rpt")

答案 1 :(得分:0)

我改变了:

cryRpt.Load(Application.StartupPath + "bincard1.rpt")

要:

cryRpt.Load(Application.StartupPath & "bincard1.rpt")

然后报告设计集复制输出目录=复制如果更新并编译为内容。

答案 2 :(得分:-1)

cryRpt.Load()中的路径错误。目前它看起来像这样:

  

C:\ Program Files \ Application Namebincard1.rpt

请注意"Application Name""bincard1.rpt"之间没有backslash。这会使路径无效。这是因为您使用+来连接会导致某些问题的路径。

相反,请考虑使用Path.Combine加入Application.StartupPath"bincard1.rpt"

cryRpt.Load(Path.Combine(Application.StartupPath, "bincard1.rpt"))

这将为您提供类似于:

的路径
  

C:\ Program Files \ Application Name \ bincard1.rpt