Solved

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

Posted on 2006-11-23
4
854 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
[X]
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
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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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