Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

DB2

Posted Feb 13, 2007

Using Crystal Reports for Visual Studio 2005 to Build Reports from DB2 9 - Part B - Page 2

By Paul Zikopoulos

Adding Your DB2 9-based Crystal Report to your Application

The Visual Studio IDE should now look like:

To embed your report within your application, perform the following steps:

1.  Expand the Crystal Reports section in the Toolbox and drag-and-drop CrystalReportViewer from the Toolbox to the designer palette as shown below:

This action places a CrystalReportViewer control within your application which your application uses to render your report.

2.  Click the CrystalReportViewer Tasks ( ) design controller:

3.  Clear the Display Group Tree and Display Status Bar check boxes. After completing this step, the Crystal Reports design controller should look like the far right WinForm:

Note: The designer controller ( ) becomes available only when you select the CrystalReportsViewer control on the design palette.

4.  Click Unlock in parent container in the design controller. Your application form should now look like:

5.  Resize the WinForm and the CrystalReportsViewer control so that they span the size of the design palette, leaving some room for another control that we’ll add later in this article. Your WinForm should now look similar to this:

6.  Bind the STAFFReportDB29 report that you built in Part A by clicking on the design controller, selecting Choose a Crystal Report, then select the STAFFReportDB29.rpt report from the Specify a Crystal Report for the control list. Click OK:

Your application is now really beginning to take shape and should look like this:

7.  Click Data>Add New Data Source, select Database, then click Next.

8.  Select the connection string that corresponds to your SAMPLE database from the Which data connection should your application use to connect to the database? list and select Yes, include sensitive data in the connection string (heh...this is just an article, so this option is OK). Click Next:

Note: If you don’t have a connection to the SAMPLE database, click New Connection to add it. If you don’t know how, refer to the “Addendum: Adding a DB2 Data Source to the Visual Studio 2005 Server Explorer” section in a previous article I’ve written which covers this process in detail.

9.  In the next page of the wizard, select the defaults and click Next.

10.  Expand Tables and select STAFF, then click Finish:

11.  You should now see the STAFF table in the Solution Explorer. Drag the STAFF object and drop it on your WinForm and resize the generated data grid so that it looks like this:

12.  Click the designer controller ( ) and ensure that Choose Data Source is bound to the STAFFBindingSource object that was automatically generated for you when you dropped the STAFF object onto the WinForm:

13.  Press F5 to build your application. It should look like this:

You can see that your report is rendered in the application along with a data grid that shows all the data in the STAFF table. Perhaps a manager wanted to navigate all the employees in an enterprise, despite the fact that the report was for the subset of the employees within the company the she manages. She could also use the controls for navigating the data set that are automatically placed on the application by Visual Studio 2005:

Notice that you also get controls for interacting (like zoom, print, refresh, and so on) with the report as well:

 

Wrapping it Up...

Now you have an application that generates a cross tab report from data that’s persisted in a DB2 9 data server. This application also presents a list of raw data that you can navigate – all from DB2 9.

You could have created all sorts of different reports or made a more complex application. For example, I’d likely add parameterization to this report such that I could choose to add different departments for comparative purposes and automatically generate a base set of statistics like standard deviation of the company’s average sales and the mean salary across departments with similar job families. Notice that you followed a very natural and native Visual Studio .NET development experience and were agnostic to the data server providing the data...and that’s the whole point.

» See All Articles by Columnist Paul C. Zikopoulos

About the Author

Paul C. Zikopoulos, BA, MBA, is an award-winning writer and speaker with the IBM Database Competitive Technology team. He has more than ten years of experience with DB2 and has written over sixty magazine articles and several books about it. Paul has co-authored the books: Information on Demand: Introduction to DB2 9 New Features, IBM DB2 9: New Features, DB2 Version 8: The Official Guide, DB2: The Complete Reference, DB2 Fundamentals Certification for Dummies, DB2 for Dummies, and A DBA's Guide to Databases on Linux. Paul is a DB2 Certified Advanced Technical Expert (DRDA and Cluster/EEE) and a DB2 Certified Solutions Expert (Business Intelligence and Database Administration). In his spare time, he enjoys all sorts of sporting activities, running with his dog Chachi, and trying to figure out the world according to Chloë – his new daughter. You can reach him at: mailto:paulz_ibm@msn.com.

Trademarks

IBM and DB2 are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both.

Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.

UNIX is a registered trademark of The Open Group in the United States and other countries.

Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.

Other company, product, and service names may be trademarks or service marks of others.

Copyright International Business Machines Corporation, 2006. All rights reserved.

Disclaimer

The opinions, solutions, and advice in this article are from the author’s experiences and are not intended to represent official communication from IBM or an endorsement of any products listed within. Neither the author nor IBM is liable for any of the contents in this article. The accuracy of the information in this article is based on the author’s knowledge at the time of writing.



DB2 Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 



















Thanks for your registration, follow us on our social networks to keep up-to-date