带命令的水晶报表

发布于 2024-10-19 16:02:47 字数 1457 浏览 0 评论 0原文

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

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

请询问我是否没有表达清楚。

谢谢, 头像

Crystal report (.rpt) file can be created by standard report creation wizard at that point user have two options. Either can add command or select tables from database.
You can also create crystal report file (.rpt) from visual studio 2010 -> add new itme -> crystal report. Now i am changing database name of rpt file at run time.

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
            {

            }
        }

Code does not work when rpt file used command. While debugging , rd(reportdocument).DataBase.Tables[0].Name = "Command"
if rpt file has manually selected tables
rd(reportdocument).DataBase.Tables[0].Name = "EmployeeTable" (Name of the table)

code wont change the connectionInfo of the table when it finds command.

Please ask if i dint make my self clear.

Thanks,
N Avatar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2024-10-26 16:02:47

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

然后我添加了

crystalreportviewer.ViewerCore.RefreshReport();

问题已解决。
谢谢,

Couple of errors.
I was using using CrystalDecisions.Windows.Forms.CrystalReportViewer now i am using SAPBusinessObjects.WPF.Viewer.CrystalReportsViewer.

Then I added

crystalreportviewer.ViewerCore.RefreshReport();

Problem solved.
Thanks,
N

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文