【问题标题】:Crystal Report Always prompting for Date ParameterCrystal Report 总是提示输入日期参数
【发布时间】:2014-01-23 02:29:17
【问题描述】:

我目前在将日期参数从 vb.net 传递到 Crystal Report XI 时遇到问题

我写了很多报告,在传递参数时从来没有遇到过问题,但话说这是我第一次传递日期

它似乎完全忽略了我传递的参数并不断要求我输入开始日期(SDate)和结束日期(EDate)

这是我的代码

Public Sub GenerateInvoiceByDate(ByVal SDate As Date, ByVal EDate As Date, ByVal boolByAccount As Boolean, ByVal strAccountRef As String)
    Dim strSelectionText As String = ""
    Dim theReport As New ReportDocument
    theReport.FileName = strReportLocation & "Invoice2.rpt"

    theReport.SetParameterValue("SDate", Format(SDate, "dd/MM/yyyy"))
    theReport.SetParameterValue("EDate", Format(EDate, "dd/MM/yyyy"))
    theReport.SetParameterValue("AccountRef", strAccountRef)

    If boolByAccount = True Then
        'generate an invoice for a specific customer account between two dates
        strSelectionText = "{InvoiceHeader.CustomerRef}= {?AccountRef} and {InvoiceHeader.CreatedOn} in {?SDate} to {?EDate}"
    Else
        'generate all invoices between two dates
        strSelectionText = "{InvoiceHeader.CreatedOn} in {?SDate} to {?EDate}"
    End If

    theReport.RecordSelectionFormula = strSelectionText

    theReport.SetDatabaseLogon(strDatabaseUser, strDatabasePassword)

    ReportView.CRView.ReportSource = theReport

    ReportView.ShowDialog()

End Sub

我假设问题出在 Crystal 报告所期望的日期格式上,因此我引入了 Format() 方法。我已经确认水晶期待一个日期而不是日期时间。这两个日期通过以下代码传递给方法

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    CropTrackMod.GenerateInvoiceByDate(dtpSDate.Value, dtpEDate.Value, chkByAccount.Checked, txtAccountRef.Text)

End Sub

我的想法开始用完了,如果有人能阐明我的问题,我将不胜感激。

提前谢谢大家

更新: 我现在更改了我的代码,如下所示。如果我设置了开始日期和结束日期,那么它可以正常工作。当我尝试在 boolaccount = true 时设置帐户引用时,我收到“AccountRef”提示。我只是不明白为什么它一直在失去那个价值。

这是我更新的代码

'Test Sub for adding parameter fields to crystal reports dynamicly
Public Sub TESTGenerateInvoiceByDate(ByVal SDate As DateTime, ByVal EDate As DateTime, ByVal boolByAccount As Boolean, ByVal strAccountRef As String)
    Dim strSelectionText As String = ""
    Dim theReport As New ReportDocument
    theReport.FileName = strReportLocation & "Invoice2.rpt"
    'theReport.Load(strReportLocation & "Invoice2.rpt")

    ReportView.CRView.ReuseParameterValuesOnRefresh = True

    If boolByAccount = True Then
        theReport.SetParameterValue("SDate", SDate)
        theReport.SetParameterValue("EDate", EDate)
        theReport.SetParameterValue("AccountRef", strAccountRef.ToUpper.ToString)
        'theReport.SetParameterValue("Changed", "True")
        'theReport.SetParameterValue("InvoiceRef", "")
        'theReport.SetParameterValue("New", "True")

        'generate an invoice for a specific customer account between two dates
        strSelectionText = "{InvoiceHeader.CustomerRef} = {?AccountRef} and {InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
    Else
        theReport.SetParameterValue("SDate", SDate)
        theReport.SetParameterValue("EDate", EDate)
        theReport.SetParameterValue("AccountRef", "")
        'theReport.SetParameterValue("AccountRef", strAccountRef)
        'theReport.SetParameterValue("Changed", "True")
        'theReport.SetParameterValue("InvoiceRef", "")
        'theReport.SetParameterValue("New", "True")

        'generate all invoices between two dates
        strSelectionText = "{InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
    End If

    theReport.RecordSelectionFormula = strSelectionText
    ReportView.CRView.ReportSource = theReport



    theReport.SetDatabaseLogon(strDatabaseUser, strDatabasePassword)

    'ReportView.CRView.Refresh()

    ReportView.ShowDialog()

End Sub

如果我在 showdialog 的 sub 末尾插入断点,我可以看到报告文档的“HasRecords”属性的值为 “HasRecords = {“Missing parameter values.”}“

我在报表设计器中确认只有3个参数字段

我可以确认,如果我在报表查看器提示报表时手动输入值,报表确实有效。

【问题讨论】:

    标签: vb.net date parameters crystal-reports crystal-reports-xi


    【解决方案1】:

    我很高兴地说我现在已经解决了上面遇到的问题

    这是由于我设置报告文档属性的顺序

    我需要在设置参数值之前提供记录选择公式

    我的工作代码如下

    Public Sub GenerateInvoiceByDate(ByVal SDate As DateTime, ByVal EDate As DateTime, ByVal boolByAccount As Boolean, ByVal strAccountRef As String)
        Dim strSelectionText As String = ""
        Dim theReport As New ReportDocument
        theReport.FileName = strReportLocation & "Invoice2.rpt"
        'theReport.Load(strReportLocation & "Invoice2.rpt")
    
        ReportView.CRView.ReuseParameterValuesOnRefresh = True
    
        If boolByAccount = True Then
            'generate an invoice for a specific customer account between two dates
            strSelectionText = "{InvoiceHeader.CustomerRef} = {?AccountRef} and {InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
            theReport.RecordSelectionFormula = strSelectionText
    
            theReport.SetParameterValue("SDate", SDate)
            theReport.SetParameterValue("EDate", EDate)
            theReport.SetParameterValue("AccountRef", strAccountRef.ToUpper.ToString)
            theReport.SetParameterValue("Changed", "True")
            theReport.SetParameterValue("InvoiceRef", "")
            theReport.SetParameterValue("New", "True")
    
        Else
            'generate all invoices between two dates
            strSelectionText = "{InvoiceHeader.CreatedOn} >= {?SDate} and {InvoiceHeader.CreatedOn} <= {?EDate}"
            theReport.RecordSelectionFormula = strSelectionText
    
            theReport.SetParameterValue("SDate", SDate)
            theReport.SetParameterValue("EDate", EDate)
            theReport.SetParameterValue("AccountRef", "")
            theReport.SetParameterValue("AccountRef", strAccountRef)
            theReport.SetParameterValue("Changed", "True")
            theReport.SetParameterValue("InvoiceRef", "")
            theReport.SetParameterValue("New", "True")
    
    
    
        End If
    
        ReportView.CRView.ReportSource = theReport
    
    
    
        theReport.SetDatabaseLogon(strDatabaseUser, strDatabasePassword)
    
        'ReportView.CRView.Refresh()
    
        ReportView.ShowDialog()
    
    End Sub
    

    祝所有帮助的人好运和坦克

    【讨论】:

      【解决方案2】:

      您可能正在将字符串值传递给日期参数。 改变这一行: theReport.SetParameterValue("SDate", Format(SDate, "dd/MM/yyyy")) 和: theReport.SetParameterValue("SDate", SDate)

      【讨论】:

      • 你是对的,我相信这是作为字符串传递的,尽管它不再提示我进行更改时的日期。我删除了所有参数字段并重新开始。我用 SDate 和 EDate 让它稳定了,然后我在报告中引入了另一个参数字段,它现在提示输入“AccountRef”。搞不定
      • AccountRef 有没有可能是一个数字?
      • 很遗憾没有。它是客户帐户参考。这方面的一个例子是“大卫”。我已确保 CR 中的参数字段设置为静态字符串
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-05
      • 1970-01-01
      相关资源
      最近更新 更多