【问题标题】:SAP Crystal Report : Subreport not showing data in productionSAP Crystal Report:子报表未显示生产中的数据
【发布时间】:2023-03-21 03:52:02
【问题描述】:

我有一个主报告和 5 个子报告,除了 1 个子报告之外,一切都运行良好。

在开发模式下,当我预览主报告时,所有子报告都完美显示数据,尤其是子报告“Symptom/s”很好:

但在生产模式下,子报告“Symptom/s”没有出现:

 private void loadReport(Int64 appointmentID)
    {
        try
        {
            rd = new ReportDocument();
            //For main patient record
            SqlCommand cmd1 = new SqlCommand("st_getPatientBill", MainClass.con);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.AddWithValue("@appID", appointmentID);
            SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
            DataTable dt1 = new DataTable();
            da1.Fill(dt1);
            rd.Load(Application.StartupPath + "\\Reports\\PrescriptionReport.rpt");
            rd.SetDataSource(dt1);

            ConnectionInfo ci = new ConnectionInfo();
            ci.DatabaseName = "cms";
            ci.UserID = "sa";
            ci.Password = "12345";
            ci.ServerName = "DESKTOP-753VMJS";
            Tables tables = rd.Database.Tables;
          
            SqlCommand cmd4 = new SqlCommand("st_getInternalMedicine", MainClass.con);
            cmd4.CommandType = CommandType.StoredProcedure;
            cmd4.Parameters.AddWithValue("@appID", appointmentID);
            SqlDataAdapter da4 = new SqlDataAdapter(cmd4);
            DataTable dt4 = new DataTable();
            da4.Fill(dt4);

            rd.Subreports[0].SetDataSource(dt4);

            //For external medicine
            SqlCommand cmd3 = new SqlCommand("st_getExternalMedicine", MainClass.con);
            cmd3.CommandType = CommandType.StoredProcedure;
            cmd3.Parameters.AddWithValue("@appID", appointmentID);
            SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
            DataTable dt3 = new DataTable();
            da3.Fill(dt3);

            rd.Subreports[0].SetDataSource(dt3);



            //For disease 
            SqlCommand cmd5 = new SqlCommand("st_getPatientDiseaseWRTAppointment", MainClass.con);
            cmd5.CommandType = CommandType.StoredProcedure;
            cmd5.Parameters.AddWithValue("@appID", appointmentID);
            SqlDataAdapter da5 = new SqlDataAdapter(cmd5);
            DataTable dt5 = new DataTable();
            da5.Fill(dt5);

            rd.Subreports[0].SetDataSource(dt5);


            //For symptoms 
            SqlCommand cmd6 = new SqlCommand("st_getPatientSymptomsWRTAppointment", MainClass.con);
            cmd6.CommandType = CommandType.StoredProcedure;
            cmd6.Parameters.AddWithValue("@appID", appointmentID);
            SqlDataAdapter da6 = new SqlDataAdapter(cmd6);
            DataTable dt6 = new DataTable();
            da6.Fill(dt6);

            rd.Subreports[0].SetDataSource(dt6);

            //For tests 
            SqlCommand cmd7 = new SqlCommand("st_getPatientTestWRTAppointment", MainClass.con);
            cmd7.CommandType = CommandType.StoredProcedure;
            cmd7.Parameters.AddWithValue("@appID", appointmentID);
            SqlDataAdapter da7 = new SqlDataAdapter(cmd7);
            DataTable dt7 = new DataTable();
            da7.Fill(dt7);

            rd.Subreports[0].SetDataSource(dt7);

            //For internal medicine
            foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
            {
                TableLogOnInfo tableLogonInfo = table.LogOnInfo;
                tableLogonInfo.ConnectionInfo = ci;
                table.ApplyLogOnInfo(tableLogonInfo);
            }
            crystalReportViewer1.ReportSource = rd;
            crystalReportViewer1.RefreshReport();

        }
        catch (Exception ex)
        {
            if (rd != null)
            {
                rd.Close();
            }
        }
    }

详情如上

【问题讨论】:

    标签: crystal-reports report subreport


    【解决方案1】:

    我可以建议检查以下内容: a) 尝试查找报表中所有不起作用的表格、对象 (特别尝试在设计时将子报表连接到不同的开发服务器,它会揭示子报表中对象的隐藏依赖关系

    b) 不要忘记在完成任何更新后重新导入子报表:)

    b) 尝试通过以下过程连接所有表对象: (将其应用于主报告(_reportDocument)

    CrystalDecisions.Shared.TableLogOnInfo tableLogOnInfo = new CrystalDecisions.Shared.TableLogOnInfo();

            tableLogOnInfo.ConnectionInfo.ServerName = this.DbServer;
            tableLogOnInfo.ConnectionInfo.DatabaseName = this.DbCatalog;
            tableLogOnInfo.ConnectionInfo.Password = this.DbPassword;
            tableLogOnInfo.ConnectionInfo.UserID = this.DbUser;
            tableLogOnInfo.ConnectionInfo.IntegratedSecurity = this.DbIntegratedSecurity;
    
            foreach (Table tbl in _reportDocument.Database.Tables)
            {
                tbl.ApplyLogOnInfo(tableLogOnInfo);
            }
    
            foreach (Section sec in _reportDocument.ReportDefinition.Sections)
            {
                foreach (ReportObject obj in sec.ReportObjects)
                {
                    if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                    {
                        string subDocName = ((SubreportObject)obj).SubreportName;
                        ReportDocument subDoc = ((SubreportObject)obj).OpenSubreport(subDocName);
                        foreach (Table tbl in subDoc.Database.Tables)
                        {
                            tbl.ApplyLogOnInfo(tableLogOnInfo);
                        }
                    }
                }
            }
    

    P.

    【讨论】:

      猜你喜欢
      • 2011-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多