I am porting my application from crystal 8.5 written in C++ to crystal 2008 in .net.
Here I am not making use of crystal report viewer neither I am creating .rpt in .net code.
I have a set of already created .rpt files.
I have written a function in .net to export the crystal report.
Its a generic function and will be called for multiple crystal reports.
I am passing the parameter values to the report by making use of the following function :
ReportDocument repDoc;
repDoc.SetParameterValue(APPTYPE, strNextToken[0]);
repDoc.SetParameterValue(COMPORROLETYPE, strNextToken[1]);
Similarly I are setting other parameter values.
The problem here is that, all the reports do not have parameter fields defined that I am trying to set.
They may be present for one report and absent for another. In this case , if the report does not have a particular parameter
field, then it gives error on setting parameters and subsequently fails.
Now I want to find out through code what all parameter fields are defined in the report. Then I will only set those
parameter fields?
Please guide how can this be done.
Thanks
Sonam
Request clarification before answering.
I got all the parameter fields of the report making use of the functionality below:
CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions crParameterdef;
crParameterdef = repDoc.DataDefinition.ParameterFields;
foreach (CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition def in crParameterdef)
{
if (def.Name.Equals(DBHOSTNAME)) // check if parameter exists in report
{
repDoc.SetParameterValue(DBHOSTNAME, strHostName); // set the parameter value in the report
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nice piece of code and thank you for that. I really appreciate anyone sharing their knowledge and wisdom.
Still, remember that this code ( with a bit of a tweak to list all the params) will only show you all the parameters defined in the report. Not which of those are actually used in the report. Nor will it tell you where in the report the param is used.
Ludek
Not as trivial as you might think. You will have to loop through all the sections of the report looking for the objects you need. I don't have a code specific to parameters, but looping through al the sections would be something like the code below. But... this will only show you parameters in a section. It will not show you parameters used in a formula, record selection formula, group selection formula, text field or a conditional formula. In order to get those parameters, you's have to parse out each of those objects looking for parameters. And this is probably not an exhaustive list of places to look for a parameter in the report. I get a headache just thinking about this...
Dim crSections As Sections
Dim crSection As Section
Dim crSubreportObject As SubreportObject
'set the crSections object to the current report's sections
crSections = crReportDocument.ReportDefinition.Sections
'loop through all the sections to find all the report objects
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
'loop through all the report objects to find all the subreports
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject Then
'you will need to typecast the reportobject to a subreport
'object once you find it (***you'd go to setting the parameter here - or not...)
crSubreportObject = CType(crReportObject, SubreportObject)
'open the subreport object
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
'set the database and tables objects to work with the subreport
Ludek
Follow us on Twitter http://twitter.com/SAPCRNetSup
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Moved to .NET Development - Crystal Reports forum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Please provide the version of the dll ' CrystalDecisions.CrystalReports.Engine'.
Is the code working fine for the reports who contain the parameter?
To use the same function for all the reports, In the same function try checking whether the report contains the parameters, and which parameters are present in that particular report. This can be done by accessing the report objects and their properties.
Download the Developer library for Crystal Reports .NET SDK from here, It will help in the code.
[http://www.sdn.sap.com/irj/boc/sdklibrary#section7|http://www.sdn.sap.com/irj/boc/sdklibrary#section7]
Thanks,
Bhushan.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.