1
votes

I have write code to display data using crystal reports. I have set parameter fields but it seems like it's not functioning well. Here is an example:

Database

   1/12/2012        A
   5/12/2012        B
   9/12/2012        C
   13/12/2012       D

Conditions used to display report:
Start date = 1/12/2012
End date = 15/12/2012

Here it just displays data for 13/12/2012 - D but with

Start date = 1/12/2012
End date = 9/12/2012

it displays all the data:

   1/12/2012-A
   5/12/2012-B
   9/12/2012-C
   13/12/2012-D

Here is my vb.net code:

    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

Here's the condition in crystal report:

{1BK.edate}=({?toDate} TO {?fromDate})
2
what is the datatype of eDate? - Patrick Guimalan
I use Date/Time. using ms access - mis_PG
when you run the report in CR does it work correctly? - Jeremy Peck

2 Answers

0
votes

I'd try in this order:

  1. Change selection criteria to {1BK.edate} = ({?fromDate} to {?toDate})
  2. Change selection criteria to {1BK.edate} >= {?fromDate} and {1BK.edate} <= {?toDate}
  3. Change selection criteria to {1BK.edate} >= '#' + {?fromDate} + '#' and {1BK.edate} <= '#' + {?toDate} + '#' (make sure your parameters are strings in this instance
0
votes

it works when a change parameter field in crystal report to

Date

then the condition is

{1BK.edate} = ({?fromDate} to {?toDate})