开发者

Crystal Reports dynamic parameters values

I have crystal report with dynamic parameter (for example, linked on table COUNTRIES in some datebase). How can i programmatically get allowed values for this parameter (list of countries)? For static i can get default values using :

        ReportDocument rd = new ReportDocument();
    开发者_运维技巧    rd.Load(reporthPath);
        rd.ParameterFields; // contains params with default values collections

Dynamic parameters has no items in DefaultValues collection. I can retrieve existing connections for report, but where i can get relation between connection and dynamic parameters?


It's not possible to do that in Crystal Reports. It's better to not use dynamic parameter field; they make your report unnecessary slow. Instead convert them to a static parameter an fill the default values from your code; that's much faster plus you know what the accepted values are.


the above answer is incorrect - as of Crystal Reports XI (at least that's where my information comes from) it is possible; see http://devlibrary.businessobjects.com/BusinessObjectsXIR2/en/en/CrystalReports_dotNET_SDK/crsdk_net_doc/doc/crsdk_net_doc/html/crtsktutorialsrdparametersdiscrete.htm, particularly parts 2(Creating a Report with Parameters) and 5(Create a ListBox Control that Displays Default Parameters)

basically the list of possible values can be taken from the default values list,

thanks,

MD-Tech


Improving on the existing answers a little bit after running this problem to ground myself:

A ParameterField with a Static list of values has these values as items in its DefaultValues collection. The problem is that a ParameterField with a Dynamic list does not have these values pre-populated and the API does not seem to have a mechanism to query them.

A workaround involves using a Static list instead of a Dynamic one, but there may be hundreds of acceptable values which may change over time. Unless remembering to change the report(s) is appealing, a Dynamic list makes sense in this context.

In addition, using the CrystalDecisions.ReportAppServer.DataDefModel.ParameterField reveals a property BrowseField. BrowseField has properties TableAlias and Name which you can query with ADO.NET. However, BrowseField is only populated for Static parameters; it is null when using a Dynamic parameter. This is currently documented as a "needs fixed" on SAP's knowledge base, Article 2114469.

So, once you somehow get the table and column name, use ADO.NET to query the database and stick those values into the DefaultValues collection of the Dynamic parameter. Consider using a naming convention for the parameters to make this easier. Perhaps use a static parameter that isn't used in the report to house your table and column information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜