Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-23
4
Medium Priority
?
859 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 2000 total points
ID: 18019504
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

926 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