SAP Crystal Report:子报表未显示生产中的数据

问题描述

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

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

Development Preview

但是在生产模式下,子报表“Symptom/s”没有来:

Production Preview

 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();
            }
        }
    }

详情如上

解决方法

我建议检查以下内容: 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.

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...