Select all the columns that you need to display in the reports. I selected all of them for simplicity. Remember to add following namespaces at the top of code behind page for referencing Crystal Report objects.
Engine; using CrystalDecisions. MapPath "CrystalReport. ClearContent ; Response. WriteLine ex. Report files contain the information about last database connection, which was used in Crystal report designer.
However the password is not stored within the report file for security reasons. The password is only used to establish the database connection. This means, that we must apply logon information at runtime. In common case the code to initialize Crystal Report viewer can look like this:. However, if the report contains more than one table or stored procedure inside we need to specify connection information for each of them.
Anyway all of them need connection information to be specified. NET pages. Essentially, the authentication details are reset on a postback and need to be reassigned. If your report is complicated enough and contains inner subreports, you need to execute some additional API steps to make the report to load correctly. Actually you need to set connection info for all items inside each subreport. Recursion is the convenient way to achieve this goal. Moreover, if you need to make some changes in text or font styles, set another color in your report or subreports, you can do it programmatically.
ReportDocument class gives ReportDefinition property for these purposes. Diving into sections and report objects we can change the view of a report greatly.
The process of designing reports is far more comfortable in Crystal Reports Designer or Visual Studio plugin. The design of the report should be remained unchanged as the author planned it. All, that you need to set is the data source. The provider, which you choose to establish the connection with the database play very important role, especially if you are going to deploy your application to another environment.
As it was mentioned earlier Crystal Report files contain the information about last database connection, which was used in Crystal report designer. But if one of the target machines contains Windows 7 Vista installed, we need to choose another provider. I inferred the next remarks from my researches.
The fields of logon prompt are empty despite our predefined settings. We just update logon properties, which were stored inside rpt file as the part of a cache. I suppose, that data source and initial catalog should be also updated as the provider name. Sometimes we need to provide the way to pass parameters to a report. Obviously, that the logon prompt data is based on the report source.
But if you want to make any changes in parameters from logon prompt explicitly, you should use the next API:. To localize the interface of the viewer control we need just to specify a product locale, which has CultureInfo type.
For example, you need to specify the format of dates, which are displayed in the report. So, we can get a separate report for each localized version in this case. But also we can specify the locale programmatically. There are some cases, when we should give thought to the matter of performance. It creates a temp shadow copy and uses it to load the report into memory. May be in previous version it was so. But using reflector I found out, that CrystalDecisions.
It seems, that it was remained for backward compatibility only. A temp copy is always used to load the report into memory. Paging through the report, printing, exporting, using input forms to pass parameters to a report — all these features may visibility affect report performance. To resolve this issue, saving the report source into memory can be a good solution. End Select.
The Crystal Report. Crystal Report exported to PDF file. Related Articles. Add Comments. Thank you for the feedback. The comment is now awaiting moderation. You will be notified via email when the author replies to your comment. Please select a comment to reply. You can add your comment about this article using the form below. Make sure you provide a valid email address else you won't be notified when the author replies to your comment Please note that all comments are moderated and will be deleted if they are Not relavant to the article Spam Advertising campaigns or links to other sites Abusive content.
Please do not post code, scripts or snippets. Required Invalid Email Address. Security code:. Required Invalid security code. I declare, I accept the site's Privacy Policy. Add Comment. Disclaimer : The code samples and API available at www. You are free to use it for commercial as well as non-commercial use at your own risk, but you cannot use it for posting on blogs or other tutorial websites similar to www. All the code samples and API provided by the authors are solely their creation and neither the author nor the site are responsible if it does not work as intended.
I agree to the above terms. Download Required.
0コメント