Displaying Crystal Reports using WinForms and C#
page 4 of 7
by Eric Landes
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 75274/ 179

Logging on using a Crystal Report Document

Let's see how we can log into the report automatically.  First we need to add a button that we will use to automatically log in using the Crystal Report Document object.  The next section we will use the log on setting option in the Crystal Viewer.

First, let's drag a button over on the form.  Drag over a button from the Toolbox, Windows forms.  It should look similar to Figure 1.

Figure 1

The above figure also contains the button called "Logon Viewer" which we will talk through in the next section.  In the following code

Listing 1

Burndown rptBurndown = new Burndown();
CrystalDecisions.Shared.ConnectionInfo crDbConnection = new
  CrystalDecisions.Shared.ConnectionInfo();
crDbConnection.IntegratedSecurity = true;
crDbConnection.DatabaseName = "TfsWorkItemTracking";
crDbConnection.ServerName = "tfdbserver";
CrystalDecisions.CrystalReports.Engine.Database crDatabase =
  rptBurndown.Database;
CrystalDecisions.Shared.TableLogOnInfo oCrTableLoginInfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table oCrTable in
  crDatabase.Tables)
{
  oCrTableLoginInfo = oCrTable.LogOnInfo;
  oCrTableLoginInfo.ConnectionInfo = crDbConnection;
  oCrTable.ApplyLogOnInfo(oCrTableLoginInfo);
}
 
crystalReportViewer1.ReportSource = rptBurndown;      

In this code, we are able to log onto a report document.  First we create a new instance of the Burndown report.  We create a new ConnectionInfo object, for this instance just one will do.  If you would ever need to log onto different sources, then you need to make multiple connectioninfo objects.  We then get a Database object from the Burndown report object. 

Finally we loop through all the tables in the reports database.tables collection.  First getting TableLoginInfo objects from the report database, we set the connectioninfo property of that object to the database connection info set earlier.  Here is where you would need to make changes if you are logging into multiple data sources.


View Entire Article

User Comments

No comments posted yet.




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


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-07-19 5:12:05 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search