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): 47733/ 57

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-2024 ASPAlliance.com  |  Page Processed at 2024-04-29 2:10:51 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search