locked
Passing long string to parameter field in crystal report RRS feed

  • Question

  • User701120146 posted

    Hi,  

    I have a Crystal Report (the one bundled with Visual Studio .NET 2002). If I pass a long string as parameter, there will be exception:

    Exception Details: System.ArgumentException: Value does not fall within the expected range.

     
    [ArgumentException: Value does not fall within the expected range.]
       CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.a(Object , _* ) +905
       CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.AddCurrentValue(Object value) +199
       CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.ApplyCurrentValues(ParameterValues currentValue) +480
       CTS.RptPreview.Page_Load(Object sender, EventArgs e) in C:\ATS WEB SITE\NMSWEB\RptPreview.aspx.vb:76
       System.EventHandler.Invoke(Object sender, EventArgs e) +0
       System.Web.UI.Control.OnLoad(EventArgs e) +67
       System.Web.UI.Control.LoadRecursive() +35
       System.Web.UI.Page.ProcessRequestMain() +750

     

    Here is my Code:

                crReportDocument = New ReportDocument()

                .....

                Dim crParamFields As ParameterFields

                ....

                Dim paramFields As ParameterFieldDefinitions
                Dim paramField As ParameterFieldDefinition

                For Each paramField In crReportDocument.DataDefinition.ParameterFields
                    paramField.ApplyCurrentValues(crParamFields(paramField.ParameterFieldName, paramField.ReportName).CurrentValues)
                Next

     And it fail at the line:

                    paramField.ApplyCurrentValues(crParamFields(paramField.ParameterFieldName, paramField.ReportName).CurrentValues)

     
    Could anyone help? Thx in advance

    Xavier

     

    Monday, October 9, 2006 3:07 AM

All replies

  • User-1485923650 posted

    Hi Xavier

    I am giridhar.

    I am also facing the same issue. could you please me to resolve this issue.

    (ISSUE: I have a Crystal Report (the one bundled with Visual Studio .NET 2002). If I pass a long string as parameter, there will be exception:)

    Please mail me the answer to giridhara.anandkrishna@acs-inc.com

    Thank you

    GIRIDHAR

    Tuesday, June 21, 2011 7:11 AM
  • User363754837 posted

    You need to use somehting like this it will take it no matter how long it is

    make sure you declare your parameters

    crparameterfielddefininition as parameterfielddefinition

    crparameterfielddefininitions as parameterfielddefinitions

    And so on then do the following

    crparameterDiscreteValue.Value = your Value))

    crparameterfieldDefinitions = Session(Your report session Name).DataDefinition.parameterFields

    crparameterfielddefinition = crparameterfieldDefinitions.Item("yourparameter")

    crparameterValue = crparameterfielddefinition.CurrentValues

    crparameterValue.Clear()

    crparameterValue.Add(crparameterDiscreteValue)

    crparameterfielddefinition.ApplyCurrentValues(crparameterValue)

    finally pass you reportviewer you reportsource which should be in this case your session report name

    Hope this helps

    Wednesday, June 22, 2011 5:32 PM
  • User1196771204 posted

    hi gridhar,

    can you resolve the issue with the response from masterpage1? Please keep us updated.

    masterpage1, thanks for sharing this valuable information. Appreciate it! 

    Thursday, June 23, 2011 3:25 AM
  • User363754837 posted

    Anytime my friends.

    Thursday, June 23, 2011 2:03 PM
  • User-1485923650 posted
    Hi 
    
    Still issue is there. i m unable to resolve it. Here i am furnishing with the complete details.
    
    
    I have 1 stored procedure with couple of parameters. i am using this SP in crystal report. Here is how i declared parameters in SP.
     @StringParm1 varchar(1),    
     @StringParm2 varchar(30),    
     @StringParm3 varchar(30),    
     @StringParm4 varchar(100),    
     @StringParm5 varchar(200),    (This parameter creating me the problem)
     @StringParm6 varchar(10)    
    
    * if I pass the parameter value below 200 characters to @StringParm5 i am able to generate the report with out any issues.
    * If the parameter value exceeds 200 character i am facing the below issue , here is the error message.
    ( ERROR DETAILS : An unhandled exception of type 'System.ArgumentException' occurred in crystaldecisions.crystalreports.engine.dll Additional information: Value does not fall within the expected range.)
    
    
    
    FIRST i modified the SP and changed the @StringParm5 varchar(200) to @StringParm5 varchar(6000).
    Still i am getting the same issue. dont know whats wrong .
    
    Here is the VB.NET code (version: VS 2002)
    
    
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As ParameterValues
            Dim crParameterDiscreteValue As ParameterDiscreteValue
    
            crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields()
    
            For Each crParameterFieldDefinition In crParameterFieldDefinitions
                If crParameterFieldDefinition.ReportName = "" Then
                    Dim ParmValue
                    ParmValue = System.DBNull.Value
                    Select Case crParameterFieldDefinition.ParameterFieldName
                        Case "@RptNum"
                            ParmValue = CInt(RptNum)
                        Case "@StringParm1"
                            ParmValue = StringParm1
                        Case "@StringParm2"
                            ParmValue = StringParm2
                        Case "@StringParm3"
                            ParmValue = StringParm3
                        Case "@StringParm4"
                            ParmValue = StringParm4
                        Case "@StringParm5"
                            ParmValue = StringParm5
                        Case "@StringParm6"
                            ParmValue = StringParm6
                        Case "@StringParm7"
                            ParmValue = StringParm7
                        Case "@StringParm8"
                            ParmValue = StringParm8
                        Case "@StringParm9"
                            ParmValue = StringParm9
                        Case "@StringParm10"
                    End Select
    
                    If Not IsDBNull(ParmValue) Then
    
                        crParameterDiscreteValue = New ParameterDiscreteValue()
    
                        crParameterDiscreteValue.Value = ParmValue
                        crParameterValues = crParameterFieldDefinition.CurrentValues
                        crParameterValues.Clear()
                        crParameterValues.Add(crParameterDiscreteValue)
                        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
                    End If
    
                End If
            Next
    
    
    
    PLEASE HELP ME TO RESOLVE THE ISSUE.
    
    
    THANK YOU IN ADVANCE.
    GIRIDHAR
    
    
    
    
    Friday, June 24, 2011 3:31 AM
  • User363754837 posted

    Well for starters, you should make your stored procedure variable as nvarchar(max) if you don't know how many characters you will return and secondly if you already have these variables set in your stored procedure they should be imported automatically by crystal report.

    A work around your stored procedure is to create a table join staight out of your report and then create your parameters that way you don't have to deal with the size issue because there is no way that your variable size should be larger than the table field data it will not work i will be more than glad to help you with this. because your problem seems to be simple you just need to take the right approach.

    Hope this help.

     

    Friday, June 24, 2011 11:37 AM
  • User363754837 posted

    you can do your select statement in your stored procedure also that way you don't have to do it in code here is an example of passing parameters to your report

       Dim reportPath As String = Server.MapPath("Your Report Name.rpt")
            myreportDocument = New ReportDocument
            myreportDocument.Load(reportPath)
            logon(connectioninfo, myreportDocument)
            Session.Add("ReportSession", myreportDocument)
            myreportDocument = CType(Session("ReportSession"), CrystalDecisions.CrystalReports.Engine.ReportDocument)

            'Pass in parameter first Value
            crparameterDiscreteValue.Value = Your Parameter Value or control
            crparameterfieldDefinitions = Session("NTesting").DataDefinition.parameterFields
            crparameterfielddefinition = crparameterfieldDefinitions.Item("@YourParameterName")
            crparameterValue = crparameterfielddefinition.CurrentValues
            crparameterValue.Clear()
            crparameterValue.Add(crparameterDiscreteValue)
            crparameterfielddefinition.ApplyCurrentValues(crparameterValue)

            'Pass in second Parameter Value
            crparameterDiscreteValue.Value = Your Parameter Value or control
            crparameterfieldDefinitions = Session("NTesting").DataDefinition.parameterFields
            crparameterfielddefinition = crparameterfieldDefinitions.Item("@YOurParameterName")
            crparameterValue = crparameterfielddefinition.CurrentValues
            crparameterValue.Clear()
            crparameterValue.Add(crparameterDiscreteValue)
            crparameterfielddefinition.ApplyCurrentValues(crparameterValue)
            CrystalReportViewer1.ReportSource = Session("ReportSession")

    Friday, June 24, 2011 11:44 AM
  • User-1485923650 posted

    Hi MasterPage

    this is related to the Crystal Reports. "QUERY ENGINE ERROR : CANNOT OBTAIN ERROR MESSAGE FROM THE SERVER"

    Actually "PASSING LONG STRING TO PARAMETER FIELD IN CRYSTAL REPORT" problem has been solved.

    However i hve some other issues in the crystal report.

    I have 1 stored procedure with couple of parameters. say 5 parameters and i have been using this SP in crystal report. and i am able to generate the report as well.

    Now i have added 3 more parameter to the above SP. to reflect these on the crystal report i have done the below steps.

    in VS.NET Evnironment -->In Field Explorer -->RightClick DataSource Location --> Set DataSource Location pop up window came and I selected the SP from the CurrentDataSource.

    Below in REPLACE WITH --> CREATE NEW CONNECTION -->ODBC(RDO)--> MAKE NEW CONNECTION--> WITH THE RESPECTIVE DATABASE , I selected the SP and in the right side i CLICK on UPDATE button --> as soon as i got ENTER PARAMETER VALUE pop up window displayed ,here i am able to see all the parameters which are added recently ... ---> OK , HERE I GOT AN ERROR.

    "QUERY ENGINE ERROR : CANNOT OBTAIN ERROR MESSAGE FROM THE SERVER"

    Why i am getting this error? i got this error for this crystal report , before i have done for the other 2 reports , its working fine....

    Please help me to resolve the issue .

    Thank you

    Giridhar


    Friday, July 8, 2011 1:41 AM
  • User1196771204 posted

    i believe you have raised another thread for this problem :-)

    Friday, July 8, 2011 11:43 PM