日期:2014-05-18  浏览次数:20499 次

水晶报表无法打开行集问题
我用C#和.net做水晶报表,是要在主报表中添加一个已有的子报表,两个表之间没有关联,只是为了显示才做成主报表与子报表。单个显示主报表与子报表都是没有问题的,但是两个表结合在一起就显示不了,提示说“提供的参数无效,打开行集失败”,不知道是什么原因? 以下是程序,请大家帮忙解决!谢谢。 我刚注册,所以没有什么分数给大家,不好意思。  
  BaseClass baseClass = new BaseClass();
  SqlConnection con = baseClass.getcon();
  con.Open();

  string strsql = "select bh ,qtype,question from tb_Test order by qtype,bh asc";
  DataSet1 tb_Test = new DataSet1();
  SqlDataAdapter sda = new SqlDataAdapter(strsql, con);
  sda.Fill(tb_Test, "test");

  string strsql1 = "select tkNum ,pdNum,jdNum,testName from tb_testInfo";
  DataSet1 tb_testInfo = new DataSet1();
  SqlDataAdapter sda1 = new SqlDataAdapter(strsql1, con);
  sda1.Fill(tb_Test, "testInfo");


  ReportDocument rd = new ReportDocument();

  string FilePath = Server.MapPath("CrystalReport3.rpt");

  rd.Load(FilePath);
  TableLogOnInfo logOnInfo = new TableLogOnInfo();
  foreach (CrystalDecisions.CrystalReports.Engine.Table tb in rd.Database.Tables)
  {
  logOnInfo = tb.LogOnInfo;
  logOnInfo.ConnectionInfo.ServerName = "(local)";
  logOnInfo.ConnectionInfo.DatabaseName = "testsystem";
  logOnInfo.ConnectionInfo.Password = "sa";
  logOnInfo.ConnectionInfo.UserID = "sa";
  tb.ApplyLogOnInfo(logOnInfo);
  }

  rd.SetDataSource(tb_Test);
  this.CrystalReportViewer1.ReportSource = rd;

------解决方案--------------------
子报表需要单独给与数据登录信息。
请参考
C# code

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class _Default : System.Web.UI.Page 
{
    private ReportDocument northwindCustomersReport;

    private void ConfigureCrystalReports()
    {
        northwindCustomersReport = new ReportDocument();
        string reportPath = Server.MapPath("NorthwindCustomers.rpt");
        northwindCustomersReport.Load(reportPath);

        ConnectionInfo connectionInfo = new ConnectionInfo();
        connectionInfo.ServerName = "ENXP-50701E";
        connectionInfo.DatabaseName = "Northwind";
        connectionInfo.IntegratedSecurity = true;
        SetDBLogonForReport(connectionInfo, northwindCustomersReport);

        SetDBLogonForSubreports(connectionInfo, northwindCustomersReport);

        crystalReportViewer.ReportSource = northwindCustomersReport;
    }

    private void Page_Init(object sender, EventArgs e)
    {
        ConfigureCrystalReports();
    }

    private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
    {
        Tables tables = reportDocument.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            TableLogOnInfo tableLogonInfo = table.LogOnInfo;
            tableLogonInfo.ConnectionInfo = connectionInfo;
            table.ApplyLogOnInfo(tableLogonInfo);
        }
    }

    private void SetDBLogonForSubreports(ConnectionInfo connectionInfo, ReportDocument reportDocument)
    {
        Sections sections = reportDocument.ReportDefinition.Sections;
        foreach (Section section in sections)
        {
            ReportObjects reportObjects = section.ReportObjects;
            fo