locked
The Parameter is incorrect

    Question

  •  

    I'm working in CR10, C#, Visual Studio 2005 .NET. I've successfully developed 4 CR reports that uses parms.

    I need to add 4 new parms to each of the reports.  I thought it would go smoothly since most of the work would

    be cut-n-paste.   Unfortunately, the viewer returns a box with the message "The parameter is incorrect".  I've tried

    commenting out each of the parms, and each one returns the same error.

     

    Below is my code. The 1st two parms I had added earlier, and they are OK.  I've double checked many times

    and the parm names are correct.   In my search on the internet I've found others that had this problem, but no real answers.  Business Objects put out a patch for VS 2002 .NET KBase Article: c2018826, but i doubt that it's applicable

    to 2005.

     

    paramField = new ParameterField();

    paramField.Name = "IncludeStatus";

    ParameterDiscreteValue parameterValue = new ParameterDiscreteValue();

    parameterValue.Value = includeStatusCodes; //set to true or false

    paramField.CurrentValues.Add(parameterValue);

    paramFields.Add(paramField);                                                      //This parm is good

     

    paramField = new ParameterField();

    paramField.Name = "IncludeMaintCode";

    parameterValue = new ParameterDiscreteValue();

    parameterValue.Value = includeFunctionCodes; //set to true or false

    paramField.CurrentValues.Add(parameterValue);

    paramFields.Add(paramField);                                                    //This parm is also good

     

    paramField = new ParameterField();

    paramField.Name = "IncludeCounty";

    parameterValue = new ParameterDiscreteValue();

    parameterValue.Value = includeCounty; //set to true or false

    paramField.CurrentValues.Add(parameterValue);

    paramFields.Add(paramField);                                                  //The parameter is incorrect

     

    Any suggestion about what's wrong will be greatly appreciated

    Friday, January 18, 2008 3:24 PM

Answers


  • It sounds like your trying to add a parameter that doesn't exist in the report. You need to create new parameters using the crystal report editor.

    Also, you should access the parameters through the ReportDocument.DataDefinitions.ParameterFields collection. Then set the discrete values and don't forget to call the ApplyCurrentValues method of the ParameterFieldDefinition.

    Here's a snippet that works for me...

    Code Block

    'set a discrete value for the first parameter
                       
      Dim crParam1 As ParameterFieldDefinition = rptDoc.DataDefinition.ParameterFields.Item(0)
      Dim crParamCurVals As ParameterValues = crParam1.CurrentValues

      Dim crParamDiscreteVal As New ParameterDiscreteValue

      crParamDiscreteVal.Value = discreteParamVal

      crParamCurVals.Add(crParamDiscreteVal)
      crParam1.ApplyCurrentValues(crParamCurVals)




    Friday, January 18, 2008 5:13 PM

All replies


  • It sounds like your trying to add a parameter that doesn't exist in the report. You need to create new parameters using the crystal report editor.

    Also, you should access the parameters through the ReportDocument.DataDefinitions.ParameterFields collection. Then set the discrete values and don't forget to call the ApplyCurrentValues method of the ParameterFieldDefinition.

    Here's a snippet that works for me...

    Code Block

    'set a discrete value for the first parameter
                       
      Dim crParam1 As ParameterFieldDefinition = rptDoc.DataDefinition.ParameterFields.Item(0)
      Dim crParamCurVals As ParameterValues = crParam1.CurrentValues

      Dim crParamDiscreteVal As New ParameterDiscreteValue

      crParamDiscreteVal.Value = discreteParamVal

      crParamCurVals.Add(crParamDiscreteVal)
      crParam1.ApplyCurrentValues(crParamCurVals)




    Friday, January 18, 2008 5:13 PM
  •  

    Joe,

    Thanks for the reply.  I appreciate you taking the time to offer another alternative.

     

    In re-reading my post, I realized I wasn't clear on where I'm at in this project.

    I designed the original version of the report with the following parms:  IncludeStatus and IncludeMaintCode, which are boolean, and  Status and FuncCode which supports mulitple string values.  At this point everything was fine and worked the way I intended it to.  I collected the parm values in my own GUI and pasted it into CR.

     

    Later when I was asked to expand the selection criteria, I added IncludeCounty, IncludeDivision, County, and Division parms to the CR report using the editor as you suggested.   These parms are of the same type as the first 4 parms. I copied the code I used in my 1st version and renamed the items to match the new field names (i've taken care to ensure that i've named all the fields consistently in CR and C#)

     

    So, why does IncludeStatus and IncludeMaintCode work and IncludeCounty and IncludeDivision doesn't work

    (The parameter is incorrect)?  I also have the same problem with County and Division which are fields that contain multiple strings. 

     

    I've been studing your code snippet.  The main difference is your use of the ParameterFieldDefinition class.  It seems like there are a lot of ways to pass parm fields into CR.

     

    I found this link http://www.codeproject.com/KB/cs/loadingcrystalreport.aspx which I've used to help me to this point.  In it the author even addresses the need to correctly match the parm names (The parameter is blah, blah)    But, I'm sure the names are correct.  Even recreated the parm and pasted the name into the new IncludeCounty.

     

    Got any thoughts about when or why to use ParameterFieldDefinition over my approach?  Or is it simply a matter that MS has given us 100 ways to skin the cat (or skin ourselves)?

    thanks, again.

    Danny

     

     

    Friday, January 18, 2008 9:06 PM
  •  

    Joe,

    FYI.  The problem was I wasn't seeing the forest(the .rpt file) for the trees (my C# code).  That is, at running time I was loading an older version of the CR report which didn't have my new parms.   Gee, that's was a basic programming oversight on my part.

    You were correct, I hadn't defined the parms.  Thanks for your help.

    Danny

    Tuesday, January 22, 2008 7:02 PM