Sample Application: FFAssist using Crystal .NET for Visual Studio 2005 - Part 3
page 4 of 5
by Eric Landes
Feedback
Average Rating: 
Views (Total / Last 10 Days): 25048/ 112

Displaying the Report with the Data Object

In the downloadable project, the default.aspx file has a CrystalViewer object on it.  To accomplish this, I just dragged and dropped the Crystal Report Viewer onto the default.aspx page (in design mode). 

In code, binding the viewer to a report with a DataSet populated in the code-behind is similar to the methods used in VS 2003.  But, utilizing the auto-created object makes this a little easier.  First, create the object, and populate all the different tables.  Then, create a Report object and bind it to the Business Object filled with all the data. 

Listing 4: Bind the report to the viewer

CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt = 
    new CrystalDecisions.CrystalReports.Engine.ReportDocument();
oRpt.Load(@"C:\Inetpub\wwwroot\FantasyReports\PlayerWithYards.rpt");
FFAssistantDataSet oDataSet = new FFAssistantDataSet();
PlayersTableAdapter oPlayers = new PlayersTableAdapter();
String strConn = 
    ConfigurationManager.ConnectionStrings["FFAssistantConnectionString"].ToString();
oPlayers.MainConnection = strConn;
oPlayers.Fill(oDataSet.Players);
TeamsTableAdapter oTeams = new TeamsTableAdapter();
oTeams.MainConnection = strConn;
oTeams.Fill(oDataSet.Teams);
StatsTableAdapter oStats = new StatsTableAdapter();
oStats.MainConnection = strConn;
oStats.Fill(oDataSet.Stats);
PositionsTableAdapter oPositions = new PositionsTableAdapter();
oPositions.MainConnection = strConn;
oPositions.Fill(oDataSet.Positions);
oRpt.SetDataSource(oDataSet);
CrystalReportViewer1.ReportSource = oRpt;

As you see in Listing 4, I set the connection string to the connection stored in the web.config file. This should look familiar if you are already binding data to your report using Visual Studio 2003.  Just create a new ReportDocument object, and then load the report into that object.  After filling the DataSet object with data, we bind it to the ReportDocument.  Finally, the ReportDocument object is set as the ReportSource for the viewer.  Build and run the web application and you'll see the report!


View Entire Article

User Comments

Title: Crystal Report for Visual Studio 2005   
Name: waiche
Date: 2006-02-09 9:31:58 AM
Comment:
Help me ! I used Crystal Report in ASP.NET pages with VS2005. When I used ASP.NET Development Server to test, it is ok. But I used IIS Server to test, it throw an error. (Error: Report load fail). Report can't display
(my email: waicheqn@yahoo.com.vn)
Title: Problems about SQLEXPRESS db version   
Name: Sabry
Date: 2005-11-08 10:26:59 AM
Comment:
\S
Title: re: Abdullah Alshuaili   
Name: Daniel Nico
Date: 2005-11-08 7:27:47 AM
Comment:
How do you set a relative path to a datasource location in Crystal Reports? Please let me know how you did this.
Title: very nice   
Name: Abdullah Alshuaili
Date: 2005-09-07 5:22:26 PM
Comment:
Thank u very much a useful page, it was better if u set relative path instead of absloute in case of crystal reports in vb .net !!!!

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-08-03 11:03:22 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search