Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2006-11-23
4
849 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
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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