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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Datset , "Database Login" screen appears for SubReport

Status
Not open for further replies.

iamanson

Programmer
Aug 17, 2001
42
0
0
AU
I created Crystal report in .NET. Using DataSet as Datasource. If I include subreport in the report, "Database Login" appears to prompt for login. It works fine if I remove or supress the subreport.

I am using CR9. How can I solve this? Please help.
 
Hello, I'm Marisa and I'm C# programmer. I have the same problem with the subreport, Have you solved it?

Thanks,

Marisa.
 
When you are accessing the database, you will need to provide the connection information for each table in your report/subreport.
Use ConnectionInfo object to setup it at runtime before you setting ReportSource property of the Crystal Report Viewer object.
All can be changed: database name, user, password, or even new server that is different that one that was setup when the report was designed.
So iterate through all tables accessed in report/subreport and set TableLogOnInfo property for each table.
TableLogOnInfo myLoginfo= new TableLogOnInfo();
myLoginfo.ConnectionInfo.DatabaseName =
myLoginfo.ConnectionInfo.Password=
myLoginfo.ConnectionInfo.Servername=
myLoginfo.ConnectionInfo.UserId=
-obislavu-
 
This will take care of your problem.

//Assumes you have a subreport called kanban3
//Assumes you have a dataset with 2 tables....I'm referencing the second table below.
CrystalDecisions.CrystalReports.Engine.ReportDocument report;
report.OpenSubreport("kanban3").SetDataSource(ds.Tables[1]);

Scott
Programmer Analyst
<{{><
 
The following code may help you.

//- rptClass is the Crystal Report .cs generated by VS.NET
//- dsMain is the dataset that we've got from database
//- we loop the ReportObject inside the report and if subreport is found, we
// will assign the according dataset into these subreports, until all
protected virtual void BuildReport() {
if (rptClass == null || dsMain == null)
return;

rptClass.SetDataSource(dsMain);
ReportDefinition rptDef = rptClass.ReportDefinition;

foreach (ReportObject reportObj in rptDef.ReportObjects) {
if (!(reportObj is SubreportObject))
continue;

SubreportObject subreportObj = (SubreportObject) reportObj;
string strName = subreportObj.Name;
string strSubreportName = subreportObj.SubreportName;
ReportDocument reportDoc = subreportObj.OpenSubreport(strSubreportName);

if (strName == &quot;RptHeader&quot; && dsHeader != null) {
if (dataManager != null)
dataManager.SetReportHeader(dsHeader);
reportDoc.SetDataSource(dsHeader);
}
else if (strName == &quot;RptFooter&quot; && dsFooter != null) {
reportDoc.SetDataSource(dsFooter);
}
else if (strName == &quot;RptParam&quot; && dsParam != null) {
reportDoc.SetDataSource(dsParam);
}
else {
if (dsSubreports != null && dsSubreports.ContainsKey(strName) &&
dsSubreports[strName] is DataSet)
reportDoc.SetDataSource(dsSubreports[strName]);
else
reportDoc.SetDataSource(dsMain);
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top