Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have a problem I’m producing an application that adds, read and manipulate data from a Sql Server database. The application also produces reports using a data parameter. The effect that I want to achieve is this, I want my application produce reports of sales that have been done for a particular month for example I want it to display the sales that were carried out in May only. With code that i have if a user inputs a date parameter for example 01-May-2011 it shows all of the records that carried out from 01-May-2011 onwards rather than producing the records for may only.

The code that I have is shown below
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Users\sim\Documents\Visual Studio 2008\Projects\Crystal Reports Date parameter\Crystal Reports Date parameter\CrystalReport1.rpt")

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterFieldDefinitions = _
   cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
   crParameterFieldDefinitions.Item("Orderdate")
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()

    End Sub

Is it possible to use multiple parameters in one event handler (the click event) and if so how do i do it and also how do I over come my problem.
Posted
Updated 14-Oct-11 23:54pm
v2

1 solution

I changed your code a bit and it now looks like
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        cryRpt.Load("C:\Users\sim\Documents\Visual Studio 2008\Projects\Crystal Reports Date parameter\Crystal Reports Date parameter\CrystalReport1.rpt")
 
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As ParameterValues
        Dim crParameterDiscreteValue As ParameterDiscreteValue
 
        crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields

	' Begin parameter
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("Orderdate")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterDiscreteValue = New ParameterDiscreteValue
        crParameterDiscreteValue.Value = TextBox1.Text
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
	' End parameter

        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
 
End Sub


If you want to add more parameters copy statements between Begin parameter and End parameter. Then change the parameter name and the values used and it should work.

As for the fact that all line from 01-May-2011 and onwards are shown will have to do with how the data is selected. Make sure that you not only check if the Orderdate is larger than the date but also smaller than the end of the month (in this case 31-May-2011).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900