Print Page | Close Window

Pass Connection String to Subquery

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5555
Printed Date: 08 May 2024 at 5:55pm


Topic: Pass Connection String to Subquery
Posted By: ryeradio
Subject: Pass Connection String to Subquery
Date Posted: 19 Feb 2009 at 10:29am
I am dynamically passing a connection to our Crystal Reports through our web service. But when I add in a subquery it does not pass the connectionto the subquery. THis is the code I have right now..can anyone tell me what I might be doing wrong?
 
 #region Set Info for Subreports
            // Get the connection information from the main table above.
            ConnectionInfo crConnInfo = table_new.ConnectionInfo;
            // Get the reports areas.
            ReportDocument reportDoc = report.ReportDocument;
            Areas rptAreas = reportDoc.ReportDefinition.Areas;
            ReportObjects crReportObjects;
            SubreportObject crSubreportObject;
            // Holds the subreport name.
            string srptName = string.Empty;
            // Loop thru the report areas to find sections containing subreports.
            foreach (Area crArea in rptAreas)
            {
                foreach (Section crSection in crArea.Sections)
                {
                    //// Get the report objects for this section.
                    crReportObjects = crSection.ReportObjects;
                    foreach (ReportObject crReportObject in crReportObjects)
                    {
                        // Check for objects that are subreports.
                        if (crReportObject.Kind == CrReportObjectKindEnum.crReportObjectKindSubreport)
                        {
                            crSubreportObject = (SubreportObject)crReportObject;
                            // Set the subreport name.
                            srptName = crSubreportObject.SubreportName;
                            // Set the table and login credentials for the subreport.
                            foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table table in ((Database)report.SubreportController.GetSubreportDatabase(srptName)).Tables)
                            {
                                CommandTable new_table;
                                new_table = (CommandTable)table.Clone(true);
                                // Set the database login credentials.
                                new_table.ConnectionInfo = crConnInfo;
                                // Password has to be set explicitly.
                                new_table.ConnectionInfo.Password = Password;
                                //  Store the new table information for the subreport.
                                report.SubreportController.SetTableLocation(srptName, table, new_table);
                            }
                        }
                    }
                }
            }
            #endregion



Print Page | Close Window