Crystal报表未显示打印数据,而是在报表查看器上正确显示数据

时间:2017-03-06 08:59:16

标签: c# .net crystal-reports

我在水晶报告上有一些奇怪的行为。它在报表查看器上正确显示数据。但是当我尝试打印或导出相同的报告时,其打印空白报告(仅显示参数值)。我花了好几个小时试图解决这个问题,但没有运气。任何帮助都将受到高度赞赏。

代码:

                        string fr = "{tblRegistration.id} = " + sID;
                        string img = Application.StartupPath + @"\Report\" + query.rptName + ".rpt";
                        ReportDocument cryRpt = new ReportDocument();
                        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                        ConnectionInfo crConnectionInfo = new ConnectionInfo();
                        Tables CrTables;
                        cryRpt.Load(img);
                        crConnectionInfo.ServerName = Program.serverName;
                        crConnectionInfo.DatabaseName = Program.dbName;
                        crConnectionInfo.UserID = Program.saName;
                        crConnectionInfo.Password = Program.pw;
                        CrTables = cryRpt.Database.Tables;
                        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                        {
                            crtableLogoninfo = CrTable.LogOnInfo;
                            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                            CrTable.ApplyLogOnInfo(crtableLogoninfo);
                        }

                        cryRpt.SetParameterValue("date", DateTime.Now.Date);
                        cr.SelectionFormula = fr;
                        if (!print)
                            cr.ReportSource = cryRpt;
                        else
                            cryRpt.PrintToPrinter(1, true, 1, 1);

报告查看器预览:

enter image description here

报告打印/导出:

enter image description here

0 个答案:

没有答案