?
Solved

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

Posted on 2010-04-01
9
Medium Priority
?
485 Views
Last Modified: 2013-11-15
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

0
Comment
Question by:envirospatial
  • 5
  • 4
9 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 29482097
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
 

Author Comment

by:envirospatial
ID: 29502447
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 29572283
I don't know.  There should be a method or property like that.

mlmcc
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 

Author Comment

by:envirospatial
ID: 29939577
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 29978254
I don't know.  The code appears to be correct.

What are you getting?
A full report unfiltered?

mlmcc
0
 

Author Comment

by:envirospatial
ID: 30002376
Yes.  I am getting a full report.   At this point I am stumped...

any otehr suggestions are welcome..

0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 30082017
The code looks right.

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

mlmcc
0
 

Author Comment

by:envirospatial
ID: 30192352
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 30264156
Not sure I like the solution but if it works.

mlmcc
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Statement In an SAP BI BO Integration project when a BO universe is built on a BEx query, there can be an issue of unit & formatted value objects not getting generated in a BO universe for some key figures. This results in an issue whereb…
Hi, In my previous Article  (http://www.experts-exchange.com/Database/Reporting/A_15199-Introduction-to-Microstrategy.html)I discussed some basic understanding of Microstrategy that how we can get in Intro of Microstrategy (MSTR). Now it's tim…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
Suggested Courses

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question