Crystal Report始终提示输入日期参数

时间:2014-01-20 16:56:36

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

我在将日期参数从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的子末尾插入一个断点,我可以看到报告文档的“HasRecords”属性的值为“HasRecords = {”缺少参数值。“}”< /强>

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

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

2 个答案:

答案 0 :(得分: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

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

答案 1 :(得分:0)

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