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

Logging on using the CrystalViewer

Now let's look into setting the connection info using the Crystal Viewer object.  This is great if you are always using the same report in the Crystal Viewer object.  If you want to use the Viewer to display more than one report, the Report Document method probably makes more sense to use.  See Listing 2 for the C# code that sets the connection information on CrystalViewer1.

Listing 2

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

As we can see, the connection information setting is pretty much the same.  We actually do use a Report Document object to help in setting the database.  We do this by Casting the report viewer reportsource to the ReportDocument object.  Once that is done, everything else is similar to the last section.


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-20 3:49:27 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search