Error when saving parameter values as default values

GaryRasmussen
GaryRasmussen used Ask the Experts™
on
I have a C# Windows fom application that has a .NET Crystal Report Viewer.  The application opens an XML file with all the information it needs in order to display the report.  It will also save the parameter values used as default values in the report if the user wants it to.  I have one report that is giving me an error that I am unable to find anything about on the web.

System.Runtime.InteropServices.COMException (0x80042009): The parameter field default values contain some field values that are not valid.  They must be discrete values only.
   at CrystalDecisions.ReportAppServer.Controllers.ParameterFieldControllerClass.Modify(Object OldParameterField, ParameterField NewParameterField)
   at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.ApplyDefaultValues(ParameterValues defaultValue)
   at RocktonReportEngine.ReportForms.CrystalReport.ProcessReportParameters()
 
The report has 2 parameters.  A discrete parameter and a range parameter.  I have lots of reports that have both types of parameters but this report is the only one that it is causing the error so I wonder if there is something different about this report but I don't know what to look for.  Something is different about this report that my code is not accounting for.

I would be glad to include my code but for now I was just wondering if anyone has seen this before and or what it means.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
I have never seen that.

What values are you saving for the parameters?

How do you pass them to the report?

mlmcc

Author

Commented:
If you can help me out with this problem it would be fantastic!

I have attached my code in a doc that processes each parameter found in the XML and the XML that deals with parameters looks like this:

-<Parameters>-<Parameter><Name>Sales Date Range</Name>-<ParameterValues>-<RangeValue><StartValue>5/1/2012</StartValue><EndValue>5/31/2012</EndValue></RangeValue></ParameterValues></Parameter>-<Parameter><Name>Item Number</Name>-<ParameterValues><DiscreteValue>100XLG</DiscreteValue></ParameterValues></Parameter></Parameters>
Code-for-processing-parameters.docx
Top Expert 2011

Commented:
I would start with making sure that you are always dealing with discrete and range parameters.

did you try to replace:
"else //Range Value"

with
else if (valuesNode.ChildNodes(i).Name == "RangeValue")  //replace "(" in (i) with "[", it is not accepted by the comment editor
{
...
}
else
   throw an error here


may be the xml was edited and "DiscreteValue" was changed to something similar but not the same. Then the "if" will try to process the parameter as a range value instead of discrete value . Can you post the xml for the parameter which is failing ?
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Author

Commented:
The XML is correct and you can see it in the message above.

dated by: GaryRasmussenPosted on 2012-05-21 at 21:04:16ID: 37995511
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
What error are you getting?

Are the parameters static or dynamic?

mlmcc

Author

Commented:
The 2 parameters in Crystal Reports are Static.

The error I am getting is:

System.Runtime.InteropServices.COMException (0x80042009): The parameter field default values contain some field values that are not valid.  They must be discrete values only.
   at CrystalDecisions.ReportAppServer.Controllers.ParameterFieldControllerClass.Modify(Object OldParameterField, ParameterField NewParameterField)
   at CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition.ApplyDefaultValues(ParameterValues defaultValue)
   at RocktonReportEngine.ReportForms.CrystalReport.ProcessReportParameters()
Top Expert 2011

Commented:
Which line rises the error ?


Try to clear the values collections after this line:
                    //Get a collection of the current values collection
                    ParameterValues currentValues = parameterFieldDef.CurrentValues;

I don't have a project to check the exact syntax but it is something like this:
parameterFieldDef.DefaultValues.Clear()
parameterFieldDef.CurrentValues.Clear()

Why  default values are applied just in case custom values are allowed , but current values are always applied ?

Author

Commented:
I thought you had to apply the current values in order for the peport to use the parameter values.  That is why they are always applied becuase the user always wants the parameter values applied if they are passing them in.  Is that not correct?

Saving the values as default values is optional.
Top Expert 2011

Commented:
My understanding is that AllowCustomValues is just a flag for Crystal interface to allow manual insert or selection from a list. Anyway this cannot cause the error, I was just curious.

Did you try to clear the collections before to apply them and on what line is the error ?

Author

Commented:
I will try that ASAP.  I am still unable to run the customers report in Crystal in my environment so I have no way to test yet.  The error message was what displayed on the customer's machine in their environment.

I can't find anything on that error anywhere.
Top Expert 2011

Commented:
There are also strange "-" characters in the xml. Is this from IE when you coppied the data or they exist in the xml file ( or string)

-<Parameters>-<Parameter><Name>Sales Date Range</Name>-<ParameterValues>-

Author

Commented:
Sorry no, they got copied in from IE.  I have checked and the XML is clean

Author

Commented:
It ie erroring on this line

//Apply the remembered values to the defaultvalues collection
parameterFieldDef.ApplyDefaultValues(defaultValues);

Do you have a code example of how default values should be saved to the report? Perhaps I am just doing it wrong?

Author

Commented:
I think what my code was actually doing was trying to save the parameter values back to the report as default values so that from that point on, the user would not need to enter parameter values when ever they opened the report.

However the goal is not to do anything to the report itself but make it so after a user has displayed the report and they hit refresh, the viewer does not ask them to enter parameters again.  So it is a session thing and not a report thing.

Do you know how that is accomplished?
Top Expert 2011

Commented:
I am not sure that the default values support ranges.

Author

Commented:
I think I found what I need and am testing it now.

ReuseParametersOnRefresh

Author

Commented:
well poop.  The crystal report viewerr I am using does not have that property.  Most people that do have it say it doesn't work and still prompts the user shen refresh is clicked.  Do you know of any way to make the report viewer not prompt you for parameter values and just use the previous values when refrech is clicked?
Top Expert 2011
Commented:
There is an event ReportRefresh where you can tell the viewer to use the existing values or to set them.

http://social.msdn.microsoft.com/Forums/eu/vscrystalreports/thread/a8b760cf-ff57-49b5-bd02-078e85aa1b3c
Yes, I had tried that but it does not work.  Setting e.Handled = true; just stops the refresh which isn't what I wanted.  I want to be able to refresh but just using the same parameter values.  I think I may have figured out a work around.

        private void reportViewer1_ReportRefresh(object source, CrystalDecisions.Windows.Forms.ViewerEventArgs e)
        {
            reportViewer1.ReportSource = reportViewer1.ReportSource;
            e.Handled = true;
        }

Author

Commented:
Thanks Vasto!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial