Skip to Content
0
Former Member
Jun 22, 2012 at 05:44 AM

Changing database on one table in a subreport

26 Views

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