General info: C#, VS2008, .NET 3.5
I've got a form with a crystal report viewer inside it, and i'm wanting to use the one form to display all of my crystal reports. I've got it so that i can programmatically change the report, the only problem is that i have to a new method for each crystal report. I'm wanting to create a single method that can take in the database name, server name, and then the CrystalReport. The code shown below is on the form that has the crystal reports viewer.
public void setReport(string databaseName, string serverName, ReportType report)
{
crystalReportViewer1.ReportSource = report;
CrystalDecisions.Shared.ConnectionInfo crDbConnection = new CrystalDecisions.Shared.ConnectionInfo();
crDbConnection.IntegratedSecurity = false;
crDbConnection.DatabaseName = databaseName;
crDbConnection.ServerName = serverName;
crDbConnection.UserID = "userid";
crDbConnection.Password = "password";
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);
}
}