【发布时间】: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