Question

I'm using the WPF Crystal Report Viewer, and I'm reasonably happy with it.

However, I've got an issue with Subreports.

My first attempt at linking the subreports did something like this:

ReportDocument.Load(Response.ReportsPath + "\\myReport.rpt");
ConnectionInfo.DatabaseName = "myDatabase.mdb";
SetDBLogonForReport(ConnectionInfo, ReportDocument);
ReportDocument.Database.Tables[0].Location = "Table0";
ReportDocument.Database.Tables[1].Location = "Table1";
foreach (var document in ReportDocument.Subreports.OfType<ReportDocument>())
{
    SetDBLogonForReport(ConnectionInfo, document);
    document.Database.Tables[0].Location = "CommonSubreportTable";
}

Unfortunately, this does not work.

I've tried a number of different solutions. One blogger suggested that you have to set the subreports before the Main Report.

So I tried this:

ReportDocument.Load(Response.ReportsPath + "\\myReport.rpt");
foreach (var document in ReportDocument.Subreports.OfType<ReportDocument>())
{
    SetDBLogonForReport(ConnectionInfo, document);
    document.Database.Tables[0].Location = "CommonSubreportTable";
}

ConnectionInfo.DatabaseName = "myDatabase.mdb";
SetDBLogonForReport(ConnectionInfo, ReportDocument);
ReportDocument.Database.Tables[0].Location = "Table0";
ReportDocument.Database.Tables[1].Location = "Table1";

Still didn't work. Another blogger suggested that DataSets were the way to go.

So, I did that.

ConnectionInfo.DatabaseName = "MyDatabase.mdb";

foreach (ReportDocument document in ReportDocument.Subreports)
{
    document.SetDataSource(response.Dst);
}
ReportDocument.Database.Tables[0].SetDataSource(response.Dsx.Tables[0]);
ReportDocument.Database.Tables[1].SetDataSource(response.Dsc.Tables[0]);

I'm still being prompted for parameter values!!! I've been at this for HOURS!!! This should NOT be this HARD!!! Anyone have any other ideas??? Is there a hotfix or something that I've overlooked?

Was it helpful?

Solution

So I figured out the answer...

Apparently I had to set the table location based on the table name, not the index.

ConnectionInfo.DatabaseName = "myDatabase.mdb";
SetDBLogonForReport(ConnectionInfo, ReportDocument);
ReportDocument.Database.Tables[0].Location = "Table0";
ReportDocument.Database.Tables[1].Location = "Table1";

Should have been...

ConnectionInfo.DatabaseName = "myDatabase.mdb";
SetDBLogonForReport(ConnectionInfo, ReportDocument);
ReportDocument.Database.Tables["Table0"].Location = "Table0";
ReportDocument.Database.Tables["Table1"].Location = "Table1";

Once I did this, everything worked correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top