Solved

URGENT. Problem running a crystal report in ASP.NET. Missing parameter field current value error.

Posted on 2006-11-23
4
846 Views
Last Modified: 2012-08-13
Hi,

I am having a few difficulties running a crystal report (im using version 9) in visual studio 2003 for a web application. My report is pretty extensive, with a few dozen subreports but i only need one parameter to run the report (which is in the main report, not the subreports). I have set up a crystal viewer control on one of the pages and i am using a session variable from another page for the parameter field. I have place the codeto run my function on the on load page event and is shown below.

i am getting an 'Missing parameter field current value' error when i execute the code. i have stepped through the code but the error does not appear until the very end.

the subreports have a few parameters but they should all be the default values stored in the stored procedure. when running the rpeort normally the suer only ever has to input the one parameter. I think the problem might be that it is trying to put the session variable into the subreports but i am not 100% sure.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim mySessionVar As String
        mySessionVar = Session("variableName")

        ViewReport("C:\ReportName.rpt", "@bmfs_account_id", accountIDParam)
  End Sub

Friend Function ViewReport(ByVal sReportName As String, Optional ByVal paramName As String = "", Optional ByVal paramValue As String = "") As Boolean

        Dim intCounter As Integer
        Dim intCounter1 As Integer
        Dim strTableName As String
        Dim objReportsParameters As MandateReport
        Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim mySection As CrystalDecisions.CrystalReports.Engine.Section
        Dim mySections As CrystalDecisions.CrystalReports.Engine.Sections
        Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
        Dim crParameterFieldDefinitions As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
        Dim crParameterFieldDefinition As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
        Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim currValue As CrystalDecisions.Shared.ParameterValues
        Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
        Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim strParamenters As String
        Dim strParValPair() As String
        Dim strVal() As String
        Dim sFileName As String
        Dim index As Integer

        Try
            sFileName = ("C:\ReportName.rpt")
            objReport.Load(sFileName)

            intCounter = objReport.DataDefinition.ParameterFields.Count
            If intCounter = 1 Then
                If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then
                    intCounter = 0
                End If
            End If

            crParameterFieldDefinitions = objReport.DataDefinition.ParameterFields()
            crParameterFieldDefinition = crParameterFieldDefinitions.Item(0)

            currValue = crParameterFieldDefinition.CurrentValues
            paraValue = New CrystalDecisions.Shared.ParameterDiscreteValue
            paraValue.Value = Session("variableName")
            currValue.Add(paraValue)

            ConInfo.ConnectionInfo.ServerName = "serverName"
            ConInfo.ConnectionInfo.DatabaseName = "DatabaseName"

            For intCounter = 0 To objReport.Database.Tables.Count - 1
                objReport.Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
            Next

            For index = 0 To objReport.ReportDefinition.Sections.Count - 1
                For intCounter = 0 To objReport.ReportDefinition.Sections(index).ReportObjects.Count - 1
                    With objReport.ReportDefinition.Sections(index)
                        If .ReportObjects(intCounter).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
                            mySubReportObject = CType(.ReportObjects(intCounter), CrystalDecisions.CrystalReports.Engine.SubreportObject)
                            mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
                            For intCounter1 = 0 To mySubRepDoc.Database.Tables.Count - 1
                                mySubRepDoc.DataDefinition.ParameterFields.GetType.GetDefaultMembers()
                                mySubRepDoc.Database.Tables(intCounter1).ApplyLogOnInfo(ConInfo)
                            Next
                        End If
                    End With
                Next
            Next

            rptViewer.ReportSource = objReport
            rptViewer.DataBind()
            Return True

        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
    End Function



any suggestions!?

all help is greatly appreciated

Mike

0
Comment
Question by:mikestewart27
4 Comments
 
LVL 5

Accepted Solution

by:
GENTP earned 500 total points
Comment Utility
It makes sense that the error wouldn't come up when stepping through the function, since the report isn't actually "created" until you do the databind. That's it executing, and that's when the error will pop up.

But I believe the problem is that you're not actually binding the parameter to the report. This is C# code, but here is how I send params:
discVal.Value = "some value";
paramVal.Add(discVal);
rpt.DataDefinition.ParameterFields["DisplayDollarPerFoot"].ApplyCurrentValues(paramVal);

You only seem to be doing:

currValue = crParameterFieldDefinition.CurrentValues
paraValue = New CrystalDecisions.Shared.ParameterDiscreteValue
paraValue.Value = Session("variableName")
currValue.Add(paraValue)

Notice how you never tell the report what parameter you are sending the value for?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now