尽管使用push方法设置了数据集,但Crystal报表不显示任何数据 [英] Crystal report displays no data although the dataset was set using push method

查看:69
本文介绍了尽管使用push方法设置了数据集,但Crystal报表不显示任何数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是水晶报道的新手。我面临一个问题,我的报告显示没有数据,尽管数据集显示它在调试过程中确实有数据。我注意到m_rptViewReport.SetDataSource(ds);之后出现了一切错误,它显示HasRecords =功能评估已禁用,因为之前的功能评估已超时。您必须继续执行以重新启用功能评估水晶报告基本上,我我试图使用push方法将数据导出到xls文件。我正在使用VS2015,我的水晶报告汇编版本是13.0.3500.0



请看看我的代码

I'm new to crystal report. I'm facing an issue that my report show no data although the dataset showed it did have data during debugging. I noticed that everything went wrong after the line " m_rptViewReport.SetDataSource(ds); ", it show "HasRecords = Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation crystal reports" Basically, I'm trying to export the data to xls file using push method. I'm using VS2015 and my crystal report assembly version is 13.0.3500.0

Pls take a look at my code

public bool ExportToFile(DataSet ds,string fileType)
    {
        try
        {
            object obj = null;
            char[] split ={ '.' };
            CrystalDecisions.CrystalReports.Engine.ReportDocument m_rptViewReport = null;


                if (File.Exists(Request.PhysicalApplicationPath + "\\" + this.ReportFile))
                {
                   try {
                    m_rptViewReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    m_rptViewReport.Load(Request.PhysicalApplicationPath + "\\" + this.ReportFile);

                       ds.WriteXml("D:\\testfile.XML", XmlWriteMode.WriteSchema); //the output XML file does have data
                       m_rptViewReport.SetDataSource(ds);//something went wrong after this line
                   }
                   catch (Exception ex) //nothing happened here
                   {
                       throw ex;
                   }
                }
                else
                    this.SetTextTitle(Resources.GetLanguage("msgNoFile") + " " + this.ReportFile);

            if (m_rptViewReport.HasRecords){ //I added this line later and founded that the value is not TRUE
            if (m_rptViewReport != null)
            {
               SetReportParameterValue(m_rptViewReport);

                       Response.ContentType = "application/vnd.ms-excel";

                       try {
                           m_rptViewReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.Excel, Response, true, this.ReportCode);

                       }
                       catch (System.Threading.ThreadAbortException ex1)
                       {
                           //throw ex1;
                       }

            }
           }
           return true;
        }
        catch(Exception ex)
        {
           return false;
        }
    }



谢谢



什么我试过了:



- 我在app.config中添加了useLegacyV2RuntimeActivationPolicy =true,然后将其删除但两者都无效。

- 我也从我的UI中删除了所有CrystalReportViewer。


Thanks

What I have tried:

- I added useLegacyV2RuntimeActivationPolicy="true" to app.config and then removed it but both did not work.
- I also removed all CrystalReportViewer from my UI.

推荐答案

我的exprerience的最佳方法,



创建一个新的aspx页面,修改了Page_init()中的所有内容(因为没有在其他阶段工作),请确保将CrystalReportViewer放在标记视图上。



Best Approach from my exprerience,

Create a new aspx page, modified everythings inside Page_init() (because not working other stage), make sure also put CrystalReportViewer on markup views.

protected void Page_Init(object sender, EventArgs e)
        {
            rptfile = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            rptfile.Load(Server.MapPath("~/Reports/Report.rpt"));
            rptfile.SetDatabaseLogon("sa", "123", @"192.168.102.1\Database", "Data");
            rptfile.Refresh();

            .....

            OleDbDataAdapter sql = new OleDbDataAdapter(query, Connection);
                //OleDbDataAdapter sql = new OleDbDataAdapter();
                //sql.SelectCommand = new OleDbCommand(query, Connection);
            DataSet ds = new DataSet();
            sql.Fill(ds);

            rptfile.SetDataSource(ds.Tables[0]);
            this.CrystalReportViewer1.ReportSource = rptfile;
            CrystalDecisions.Shared.ConnectionInfo connectinfo = new 
            CrystalDecisions.Shared.ConnectionInfo();
            connectinfo.ServerName = @"192.168.102.1/Database";
            connectinfo.UserID = "sa";
            connectinfo.Password = "123";
            connectinfo.DatabaseName = "Data";

            CrystalDecisions.Shared.TableLogOnInfos TableLoginInfos = 
            this.CrystalReportViewer1.LogOnInfo;

            foreach (CrystalDecisions.Shared.TableLogOnInfo TableLogon in 
             TableLoginInfos)
            {
                    TableLogon.ConnectionInfo = connectinfo;
            }

            rptfile.SetParameterValue(@"param1", Class1.param1);
            rptfile.SetParameterValue(@"param2", Class2.param2);

            this.CrystalReportViewer1.HasToggleGroupTreeButton = false;
            this.CrystalReportViewer1.HasToggleParameterPanelButton = false;
            this.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
        }





在你的web.config中(帮助web服务器轻松找到路径),





Inside your web.config (to help web server find the path in easy),

<configuration>
  <configSections>
    <sectionGroup name="businessObjects">
      <sectionGroup name="crystalReports">
        <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null" />
        <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler" />
      </sectionGroup>
    </sectionGroup>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <businessObjects>
    <crystalReports>
      <rptBuildProvider>
        <add embedRptInResource="true" />
      </rptBuildProvider>
      <crystalReportViewer>
        <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
    </crystalReports>
  </businessObjects>
</configuration>


这篇关于尽管使用push方法设置了数据集,但Crystal报表不显示任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆