Crystal Reports passed parameters do not update report the first time sent vb.net

Hello,

I have a CR application that passes report parameters to a report.  The funny thing is the first time I try to send the parameters it does not update the report.  But the second time I send the parameters it works.   Hmm.. any ideas?
Thanks in advance
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If ListBox1.SelectedItems.Count = 0 Then
            MessageBox.Show("Selecionez al moins un parametre")
            Exit Sub
        End If
       
        Dim pReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        'Dim pReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim pParCollection As New CrystalDecisions.Shared.ParameterValues
        Dim pParVal As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim rpt_name As String
        rpt_name = "C:\SIDC - Asrir\Rapports\" + Trim(cb_rapport.Text) + ".rpt"
        
        Dim I As Integer
        For I = 0 To ListBox1.Items.Count - 1

            If ListBox1.GetSelected(I) = True Then
                pParVal = New CrystalDecisions.Shared.ParameterDiscreteValue   
                pParVal.Value = ListBox1.Items(I).ToString
                pParCollection.Add(pParVal)
            End If
        Next

        pReport.Load(rpt_name)

        If Trim(cb_rapport.Text).Contains("Partenaire") Then

            pReport.SetParameterValue("TypePart", pParCollection)
        Else
            pReport.SetParameterValue("IdProj", pParCollection)
            'pReport.DataDefinition.ParameterFields.Item("IdProj").ApplyCurrentValues(pParCollection)
        End If


        CrystalReportViewer1.ReportSource = pReport
        CrystalReportViewer1.Show()


    End Sub

Open in new window

envirospatialAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
I susoect the report is saved with data.  That is the default setting in Crystal.

Try adding this line after you load the report
Make sure it is before the parameters are added to the report or they will be discarded also.

    pReport.DiscardSavedData

mlmcc
0
envirospatialAuthor Commented:
thanks for your comment mimcc.

My report is defined as follows:

Dim pReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument

I do not seem to have the DiscardSavedData method available.   To further detail: My app has a set of potential reports the users chooses a report from.  No matter which report it is, the first time the code is run,  the viewed report does not reflect the parameters: however, if the routine is run again ( or any time threre after) the viewed report has the correct parameters.  It seems as if something is not being initialized until after the first report is viewed.
0
mlmccCommented:
I don't know.  There should be a method or property like that.

mlmcc
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

envirospatialAuthor Commented:
I checked again and I do not have the discard saved data method..

 I have saved the report without data, it still does not work the first time I run the report.  Once the  Viewer is opened( i.e. the code is run for the first time, with any of my reports) , it runs with the correct passed parameters.  

I still do not have an answer yet. Still lokking for help.

thanks
0
mlmccCommented:
I don't know.  The code appears to be correct.

What are you getting?
A full report unfiltered?

mlmcc
0
envirospatialAuthor Commented:
Yes.  I am getting a full report.   At this point I am stumped...

any otehr suggestions are welcome..

0
mlmccCommented:
The code looks right.

How about moving the assigning the viewer to the report above the ssigning the parameters

mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
envirospatialAuthor Commented:
Hi Mimmcc,

thanks for the suggestion.

I have found a solution that does not feel right but it works.  If I show the viewer first , then load the report, then apply the report source to the viewer,then assign parameters and then apply the report source again to the viewer it works.  However I also ran into a problem with the CR parpameter prompter dialog popping up.  If I cancel the dialog, the report ran.  So I went back to the report itself and checked  the Save data with report option.  Once I did this the prompt dialog would not show up.

Final working code below..

Thanks for your help mimcc...
 If ListBox1.SelectedItems.Count = 0 Then
            MessageBox.Show("Selecionez al moins un parametre")
            Exit Sub
        End If
       
        Dim pReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim pParCollection As New CrystalDecisions.Shared.ParameterValues
        Dim pParVal As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim rpt_name As String
        rpt_name = "C:\SIDC - Asrir\Rapports\" + Trim(cb_rapport.Text) + ".rpt"
        Dim I As Integer
        For I = 0 To ListBox1.Items.Count - 1

            If ListBox1.GetSelected(I) = True Then
                pParVal = New CrystalDecisions.Shared.ParameterDiscreteValue   
                pParVal.Value = ListBox1.Items(I).ToString
                pParCollection.Add(pParVal)
            End If
        Next
        CrystalReportViewer1.Show()
        pReport.Load(rpt_name)
        CrystalReportViewer1.ReportSource = pReport
        If Trim(cb_rapport.Text).Contains("Partenaire") Then
            pReport.SetParameterValue("TypePart", pParCollection)
        Else
            pReport.SetParameterValue("IdProj", pParCollection)
            'pReport.DataDefinition.ParameterFields.Item("IdProj").ApplyCurrentValues(pParCollection)

        End If

        CrystalReportViewer1.ReportSource = pReport

Open in new window

0
mlmccCommented:
Not sure I like the solution but if it works.

mlmcc
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB Reporting Tools

From novice to tech pro — start learning today.