Tuesday, July 21, 2009

Tip #52 – Opening a Crystal Report with Visual Studio

Using Crystal Reports from Visual Studio is relatively simple. A lightweight version of the Crystal Reports runtime and designer is included with Visual Studio allowing you to create reports within the IDE.

To create a report that uses the Advantage Crystal Reports driver you must configure your settings as outlined in Tip #51. If you do not have the full version of Crystal Reports you may need to manually copy the Advantage Crystal Driver ( crdb_ads.dll ) into the proper directory. On my system this path is: C:\Program Files\Business Objects\Common\2.8\bin.

Crystal reports can be displayed in your application using the CrystalReportViewer control. You create an instance of the report you wish to load into the viewer and then set the ReportSource property. You can use a report you created directly in Visual Studio or load an existing report.

   1: // Use a Report that is part of the project
   2: Report myReport = new Report1();
   4: // provide login
   5: myReport.SetDatabaseLogon("adssys", "");
   7: // Display the report in the viewer
   8: crvTest.ReportSource = myReport;

Loading a Crystal Report in VS

No comments: