【问题标题】:Sub Report embedded in footer of Crystal report not showing data嵌入水晶报表页脚的子报表不显示数据
【发布时间】:2014-09-03 23:31:35
【问题描述】:

我有一个水晶报表,它的页脚中嵌入了一个子报表。这些报告单独工作正常,但是当我一起运行时,我没有在子报告中获得数据。我已验证数据存在于我的 2 个数据集中,并且我获得了主报告的数据,但没有获得子报告的数据。我错过了什么? (VS 2008 4.0 .NET 框架)

// check whether the dataset is manual; if so add the subreport queries
        if (AARpt.HasSubreports)
        {
            string srName;
            string sProc;
            using (AAData dc = new AAData(AAApp, true))
            {
                for (int i = 0; i < cRpt.ReportDefinition.ReportObjects.Count; i++)
                {
                    ReportObject CurrentObject = cRpt.ReportDefinition.ReportObjects[i];
                    if (CurrentObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                    {
                        SubreportObject sr = (SubreportObject)CurrentObject;
                        rd = sr.OpenSubreport(sr.SubreportName );
                        srName = sr.SubreportName;

                        if (AARpt.SubReps.TryGetValue(srName, out sProc))
                        {
                            dsSubRept = dc.LoadSet(sProc);

                            if (dsSubRept != null)
                            {
                                DataTable dt1 = ds.Tables["MyTable"];
                                rd.SetDataSource(dt1);
                                rd.VerifyDatabase();

                            }
                            else
                            {
                                MessageBox.Show("We're sorry, but an error was encountered attempting to create this report","Utility", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return false;
                            }
                        }
                    }
                 }
            }
        }

    public DataSet LoadSet(SqlCommand _cmd)
    {
        // returns table "MyTable"
        SqlDataAdapter DA;
        DataSet DS = new DataSet();

        _cmd.CommandType = CommandType.StoredProcedure;
        _cmd.Connection = _Conn;

        DA = new SqlDataAdapter(_cmd);
        DA.Fill(DS, "MyTable");

        return DS;

    }

【问题讨论】:

    标签: c# crystal-reports


    【解决方案1】:

    我为子报表使用了错误的数据集....否则它是完美的。下面更新了代码。

    // check whether the dataset is manual; if so add the subreport queries
            if (AARpt.HasSubreports)
            {
                string srName;
                string sProc;
                using (AAData dc = new AAData(AAApp, true))
                {
                    for (int i = 0; i < cRpt.ReportDefinition.ReportObjects.Count; i++)
                    {
                        ReportObject CurrentObject = cRpt.ReportDefinition.ReportObjects[i];
                        if (CurrentObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                        {
                            SubreportObject sr = (SubreportObject)CurrentObject;
                            rd = sr.OpenSubreport(sr.SubreportName );
                            srName = sr.SubreportName;
    
                            if (AARpt.SubReps.TryGetValue(srName, out sProc))
                            {
                                dsSubRept = dc.LoadSet(sProc);
    
                                if (dsSubRept != null)
                                {
                                    // Following line added (not sure if needed, but was suggested in several spots)
                                    rd.DataSourceConnections.Clear();
                                    // The datasource in the following line changed - this was my real issue
                                    DataTable dt1 = dsSubRept.Tables["MyTable"];
                                    rd.SetDataSource(dt1);
                                    rd.VerifyDatabase();
    
                                }
                                else
                                {
                                    MessageBox.Show("We're sorry, but an error was encountered attempting to create this report","Utility", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return false;
                                }
                            }
                        }
                     }
                }
            }
        // The following is part of a class for loading data, but it is straightforward otherwise
        // I just included so you know that it returns a DataSet with a table named "MyTable"
        public DataSet LoadSet(SqlCommand _cmd)
        {
            // returns table "MyTable"
            SqlDataAdapter DA;
            DataSet DS = new DataSet();
    
            _cmd.CommandType = CommandType.StoredProcedure;
            _cmd.Connection = _Conn;
    
            DA = new SqlDataAdapter(_cmd);
            DA.Fill(DS, "MyTable");
    
            return DS;
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多