Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Format column on datatable 7 28
I need help displaying 2 models in one view in my MVC.Net application with C# code behind 5 30
Tool Box 2 32
Host asp.net pages 5 25
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

16 Experts available now in Live!

Get 1:1 Help Now