【问题标题】:Crystal Report with command带有命令的水晶报表
【发布时间】:2011-02-25 00:03:32
【问题描述】:

Crystal 报告 (.rpt) 文件可以通过标准报告创建向导创建,此时用户有两个选项。可以添加命令或从数据库中选择表。 您还可以从 Visual Studio 2010 创建水晶报表文件 (.rpt) -> 添加新的 itme -> 水晶报表。 现在我在运行时更改 rpt 文件的数据库名称

CrystalReportViewer crystalreportviewer = new CrystalReportViewer(); 
ReportDocument rd = new ReportDocument();
rd.Load(filepath);//filepath for rpt file c://command.rpt 
crystalreportviewer.ReportSource = rd; // set the source as reportdocument

 foreach (CrystalDecisions.CrystalReports.Engine.Table tb in rd.Database.Tables)
        {
            TableLogOnInfo tbloginfo = new TableLogOnInfo();
            CrystalDecisions.Shared.ConnectionInfo ci = new ConnectionInfo();
            ci.DatabaseName = databasename; ***// Changing at run time.*** User can change databasename
            ci.ServerName = "Myservername";

            ci.UserID = "userid";
            ci.Password = "userpassword";
            tbloginfo.ConnectionInfo = ci;
            tb.ApplyLogOnInfo(tbloginfo);
            try
            {

                tb.Location = ci.DatabaseName + ".dbo." + tb.Location.Substring(tb.Location.LastIndexOf(".") + 1);
            }
            catch
            {

            }
        }

当 rpt 文件使用命令时,代码不起作用。调试时,rd(reportdocument).DataBase.Tables[0].Name = "Command" 如果 rpt 文件手动选择了表 rd(reportdocument).DataBase.Tables[0].Name = "EmployeeTable"(表名)

代码在找到命令时不会更改表的连接信息。

请询问我是否要表达清楚。

谢谢, N头像

【问题讨论】:

    标签: .net database crystal-reports runtime


    【解决方案1】:

    几个错误。 我使用的是 CrystalDecisions.Windows.Forms.CrystalReportViewer 现在我使用的是 SAPBusinessObjects.WPF.Viewer.CrystalReportsViewer。

    然后我添加了

    crystalreportviewer.ViewerCore.RefreshReport();
    

    问题解决了。 谢谢, 否

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 1970-01-01
      • 2020-05-17
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多