cancel
Showing results for 
Search instead for 
Did you mean: 

Changing database on one table in a subreport

Former Member
0 Kudos

It seems like this should be easy, but I can't accomplish it.  I need to change the source database on one table in a subreport.  I originally used ApplyLoginInfo; however, that changes the database for all tables.  I can change it without a problem on the Main Report.  It is only on the subreport that I can't accomplish it.  I have finally gotten the below code to run; however, the ISCRTable doesn't have DatabaseName or ServerName and the SetTableLocation requires ISCRTable passed.

        Dim myReportClientDocument As New CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper
        myReportClientDocument = CRReport.ReportClientDocument
        myReportClientDocument.Open(ReportName, 0)
        CRReport.SetParameterValue(0, ContractFormat)
        CRReport.RecordSelectionFormula = "{TransactionItems.CNTR} = '" & Contract & "'"

        Dim SubReportNames As Strings = CRReport.ReportClientDocument.SubreportController.GetSubreportNames
        For Each SubReportName In SubReportNames
            Dim crSubReportMain As CrystalDecisions.CrystalReports.Engine.ReportDocument
            crSubReportMain = CRReport.OpenSubreport(SubReportName)
            Dim sourceDatabaseForSubreport As CrystalDecisions.ReportAppServer.DataDefModel.Database = CRReport.ReportClientDocument.SubreportController.GetSubreportDatabase(SubReportName)
            Dim subTables As CrystalDecisions.ReportAppServer.DataDefModel.Tables
            subTables = sourceDatabaseForSubreport.Tables
            Dim subTable As CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable
            Dim newTable As CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable
            For Each subTable In subTables
                newTable = subTable.Clone(True)
                If SubReportName = "Header.rpt - 03" Then
                    newTable.LogOnInfo.ConnectionInfo.DatabaseName = ExtDatabase
                    newTable.LogOnInfo.ConnectionInfo.ServerName = ExtDatabase
                    '  subTable.ApplyLogOnInfo(newTable.LogOnInfo)
                    myReportClientDocument.SubreportController.SetTableLocation(SubReportName, subTable, newTable)
                ElseIf subTable.Name = "ItemPicture" Then
                    newTable.LogOnInfo.ConnectionInfo.DatabaseName = PicDatabase
                    newTable.LogOnInfo.ConnectionInfo.ServerName = PicDatabase
                    myReportClientDocument.SubreportController.SetTableLocation(SubReportName, subTable, newTable)
                Else

                    newTable.LogOnInfo.ConnectionInfo.DatabaseName = DatabaseName
                    newTable.LogOnInfo.ConnectionInfo.ServerName = DatabaseName
                    myReportClientDocument.SubreportController.SetTableLocation(SubReportName, subTable, newTable)
                End If
            Next subTable
        Next

Thanks

 

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Wayne,

It's not a new table connection, try setting location for each, not just the new one.

Sorry it's C# but figure out how to determine which table and then set the info for that one:

foreach (CrystalDecisions.CrystalReports.Engine.ReportObject crReportObject in crReportObjects)

{

    if (crReportObject.Kind == ReportObjectKind.SubreportObject)

    {

        //you will need to typecast the reportobject to a subreport

        //object once you find it

crSubreportObject = (CrystalDecisions.CrystalReports.Engine.SubreportObject)crReportObject;

        //open the subreport object

crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

        //set the database and tables objects to work with the subreport

        crDatabase = crSubreportDocument.Database;

        crTables = crDatabase.Tables;

        //loop through all the tables in the subreport and

        //set up the connection info and apply it to the tables

        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)

        {

crConnectioninfo.ServerName = "ServerName or DSN";

crConnectioninfo.UserID = "UserName";

crConnectioninfo.Password = "PW";

crConnectioninfo.DatabaseName = "DatabaseName"; // blank if Oracle

crTableLogOnInfo = crTable.LogOnInfo;

crTableLogOnInfo.ConnectionInfo = crConnectioninfo;

crTable.ApplyLogOnInfo(crTableLogOnInfo);

        }

    }

}

Don

Answers (0)