crystal parameter onlly updates first time using SetParameterValue

I am creating a heading for my crystal report in my application, then passing it to the crystal report using the setparametervalue method of the report object. In crystal, there is a parameter called 'Report_Heading' which does not allow multiple values. There is also a formula which picks this parameter up and displays it in the heading.

This works fine the first time the report displays. But when I refresh my dataset with different data and re-display the report, the heading fails to update. The data in the report is different, but the new value for the parameter is not displayed.

The attached code is in a subroutine called from page_load.

I have tried using a report.load statement, and a report.refresh, and I'm out of ideas. Can anyone help?
Private Sub Refresh_Report(ByVal command_text As String)
 ' (code here to populate dataset1 using sql based on dropdownlists)
  Dim headingString as string = "This Report Heading"
  Dim thisreport As New CrystalReport1
  ' Report_Heading is the name of the parameter in the crystal report...
  CrystalReportViewer1.ReportSource = thisreport
End Sub

Open in new window

Who is Participating?
Hi Stewart,

Sorry I didn't get back, I didn't really know what else to suggest.  As I am looking at our .net code (which I didn't write, I'm better with Crystal than .net) I see that we are using a ParameterFields() object, and we are passing it to the viewer object, not the report object.  I must be a little brain dead at the moment, because that doesn't sound right to me, but here is a snippet of the code we use:

        Dim Rpt As ReportDocument
        Dim ParamFields As New ParameterFields()
        Rpt = GetReport(MyReport)

        Dim StartDateField As New ParameterField()
        Dim StartDate As New ParameterDiscreteValue()
        StartDateField.ParameterFieldName = "StartDate"
        StartDate.Value = MyStartDate

        crViewer.ParameterFieldInfo = ParamFields
        crViewer.ReportSource = Rpt

When you say this routine is called from page_load, and then when you 'refresh the dataset', are you calling this same routine again?  The only other thing I can think of is possibly set the report object to nothing and reload it each time.
Stewart_in_AtlantaAuthor Commented:
Hi  JGBreeden,
yes, I'm calling the same routine each time from page_load. What changes is the contents of the dropdowns and the sql that I use to generate the dataset.
I've made the following change but I get the same result - can you take a look and let me know if this is what you meant? I have replaced:
            Dim thisreport As New CrystalReport1
            Dim thisreport As CrystalDecisions.CrystalReports.Engine.ReportDocument
            thisreport = Nothing
            thisreport = New CR_Customer_Listing
            Dim reportPath As String = Server.MapPath("CrystalReport1.rpt")
Stewart_in_AtlantaAuthor Commented:
Is anyone able to help me with this? I am now desparate. I would have thought the ability to pass a parameter to a Crystal report on an page would be straight forward. Perhaps someone who does this regularly could share some sample code?

Stewart_in_AtlantaAuthor Commented:
fantastic, that works fine. One thing, in case anyone else is following this... the line Rpt = GetReport(MyReport) didn't work for me.
I replaced:
        Dim Rpt As ReportDocument
        Rpt = GetReport(thisreport)
        Dim rpt As New CrystalReport1
Thanks, I really appreciate the help.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.