Avatar of GaryRasmussen
GaryRasmussen
Flag for United States of America asked on

Error when saving parameter values as default values

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!
Crystal Reports.NET Programming

Avatar of undefined
Last Comment
GaryRasmussen

8/22/2022 - Mon
Mike McCracken

I have never seen that.

What values are you saving for the parameters?

How do you pass them to the report?

mlmcc
GaryRasmussen

ASKER
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
vasto

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 ?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
GaryRasmussen

ASKER
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 McCracken

What error are you getting?

Are the parameters static or dynamic?

mlmcc
GaryRasmussen

ASKER
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()
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
vasto

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 ?
GaryRasmussen

ASKER
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.
vasto

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 ?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
GaryRasmussen

ASKER
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.
vasto

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>-
GaryRasmussen

ASKER
Sorry no, they got copied in from IE.  I have checked and the XML is clean
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
GaryRasmussen

ASKER
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?
GaryRasmussen

ASKER
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?
vasto

I am not sure that the default values support ranges.
Your help has saved me hundreds of hours of internet surfing.
fblack61
GaryRasmussen

ASKER
I think I found what I need and am testing it now.

ReuseParametersOnRefresh
GaryRasmussen

ASKER
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?
SOLUTION
vasto

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
GaryRasmussen

ASKER
Thanks Vasto!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.