on 09-08-2008 6:34 AM
Setup - VS 2008, CR 2008 (v12.0), Win XP & C#.Net
I have a form which loops through all parameters (non-linked to sub reports, so only off the main report) and allows users to enter the values for each parameter. When hitting the preview button, I loop through all of the saved values, set the parameter field values and then add any additional filters into the recordselection formula as below. The problem i'm having is that the ReportDocument.HasRecords returns true if the ReportDocument.RecordSelectionFormula doesn't filter out every result.
For example, I have a list of customers and if I set the selection formula to filter out a specific customer, ReportDocument.HasRecors returns true, if I set the selection formula to filter something that doesn't exist i.e. customer "xk39df", the moment this line of code runs "ReportDocument.RecordSelectionFormula = rsFormula;" - ReportDocument.HasRecors returns the following exception as opposed to "False".
Message: Missing parameter values.
Source: CrystalDecisions.ReportAppServer.DataSetConversion
StackTrace: at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.hasRecords()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_HasRecords()
ErrorID: MissingParameterFieldCurrentValue
The strange thing is, it works fine if the recordselectionformula selects a record which exists in the results - all parameters have a current value except for the linked parameters.
This one has got me stumped!
foreach (ParameterFieldDefinition parameterField in ReportDocument.DataDefinition.ParameterFields)
{
var query = ReportObjects.Values.Cast<Filters>().Where(objects => objects.ParameterName == parameterField.Name.ToUpper().Trim());
foreach (var item in query)
{
parameterField.CurrentValues.Clear();
parameterField.CurrentValues.Add(item.ParameterValue);
parameterField.ApplyMinMaxValues(item.MinLength, item.MaxLengh);
parameterField.ApplyCurrentValues(parameterField.CurrentValues);
}
}
var records = ReportObjects.Values.Cast<Filters>().Where(recordSelection => recordSelection.RecordSelectionFormula.Trim().Length != 0);
foreach (var item in records)
rsFormula += item.RecordSelectionFormula;
if (rsFormula.EndsWith(" AND "))
rsFormula = rsFormula.RTrim(5);
ReportDocument.RecordSelectionFormula = rsFormula;
Hi Paul,
Try doing it through the report designer - maybe it will give you a better error message.
i.e
-load the report in the report designer
-modify the recordselection formula so that it is filtering a customer that doesn't exist
-Try to view the report.
Regards
Shawn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What order are you passing the following things in:
1. Dataset
2. Parameters
3. Recordselection Formula
4. Check for HasRecords
-Could you please try doing them in the order above - because it's possible that passing in the dataset can clear our parameters.
-Also - if you are doing any kind of filtering based on parameters / recordselection formula - it makes a lot more sense to do that at the dataset level - rather than at the report level.
Regards,
Shawn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The report has it's own ADO Datasource set in crystal reports, so I just pass the log on information to the report object before doing anything else.
this.DataSourceConnections[0].SetConnection("ServerName", "Database", "sa", "Password");
I then do a refresh before applying the parameter values (I do this because the user can preview the report more than one time by using a preview button on the parameter form without re-loading the report object)
this.Refresh();
Then I set all parameter values followed by setting the recordselection formula.
Hi Shawn, I just gave that a go and it seems to display the report just with no details section as expected.. no error messages at all?
Paul.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.