Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the database path of crystal report 1

Status
Not open for further replies.

junwebhead

Programmer
Jun 13, 2003
41
QA
Hi everyone!
I have a problem in using crystal report.
I have the code below in my form where my crystal report viewer resides and I want to programatically change the location of the database in my cystal report before it loads. I find most part of this on MSDN but I couldn't get it working.

[tt]private void frmReport_Load(object sender, System.EventArgs e) {
CrystalReport1 myReport = new CrystalReport1();
TableLogOnInfo tbllogonInfo = new TableLogOnInfo();
[/tt]
//There is a compilation error here saying there is no overload that takes 1 arguments. But the Load() method has 3 overloads.[tt]
myReport.Load(mdiContainer.strReportLoc);[/tt]
//I try to delete the line above but I encountered a run-time error here. Saying "unable to find the report in the manifest resources."
[tt]
// Loop through every table in the report.
for (int i=0; i == myReport.Database.Tables.Count - 1; i++) {
// Set the connection information for the current table.
tbllogonInfo.ConnectionInfo.ServerName = MDIForm.strDBLoc;
tbllogonInfo.ConnectionInfo.DatabaseName = MDIForm.strDBLoc;
tbllogonInfo.ConnectionInfo.UserID = "";
tbllogonInfo.ConnectionInfo.Password = "";
myReport.Database.Tables
Code:
[i]
.ApplyLogOnInfo (tbllogonInfo);
}

crystalReportViewer1.ReportSource = mdiContainer.strReportLoc;
}[/tt]


What can I do to solve my problem? I'm using MSAccess 2000 as my database. Please help me. Thanks in advance.[smile]

Jun
 
I'm using the ReportDocument object model(in a web app, but it should't make a difference), not strong typed, works fine:
Code:
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

////////////

private void GetReport()
{
 ReportDocument oRpt = new ReportDocument();
 oRpt.Load(reportPath);
 
 TableLogOnInfo logOnInfo = new TableLogOnInfo();
 ConnectionInfo connectionInfo = new ConnectionInfo();
 connectionInfo = logOnInfo.ConnectionInfo;

 connectionInfo.ServerName = reportServer;
 connectionInfo.DatabaseName = dbName;
 connectionInfo.UserID	= uId;
 connectionInfo.Password = pwd;

 for(int i=0;i<oRpt.Database.Tables.Count;i++)
 {
  oRpt.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
  if(!oRpt.Database.Tables[i].TestConnectivity)
  {
    //process connection error
  }
 }

 crViewer.ReportSource = oRpt;
}
 
Thanks for the quick and effective response! Good work. Very much appreciate it.

Jun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top