我已经编写代码来使用水晶报表显示数据。我已经设置了参数字段,但它似乎运行不正常。这是一个例子:
数据库
1/12/2012 A
5/12/2012 B
9/12/2012 C
13/12/2012 D
用于显示报告的条件:
开始日期 = 1/12/2012
结束日期 = 15/12/2012
在这里它只显示数据,13/12/2012 - D
但有
开始日期 = 1/12/2012
结束日期 = 9/12/2012
它显示所有数据:
1/12/2012-A
5/12/2012-B
9/12/2012-C
13/12/2012-D
这是我的 vb.net 代码:
Dim reader As OleDbDataReader = myCommand.ExecuteReader
If reader.Read = True Then
cryRpt = New ReportDocument()
cryRpt.Load("C:\Users\user\Documents\LabSystem\LabSystem\Report\Spec.rpt")
crParameterDiscreteValue.Value = txtDateFrom.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions("fromDate")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterDiscreteValue.Value = txtDateTo.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions("toDate")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
CrTables = cryRpt.Database.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table
For Each crTable In CrTables
crtableLogoninfo = crTable.LogOnInfo
Next
crtableLogoninfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crtableLogoninfo)
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.RefreshReport()
Else
MsgBox("No records exists")
End If
reader.Close()
Catch ex As Exception
MsgBox("Error in select query: " + ex.Message)
End Try
这是水晶报告中的条件:
{1BK.edate}=({?toDate} TO {?fromDate})