首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Crystal Subreport提示登录

Crystal Subreport提示登录
EN

Stack Overflow用户
提问于 2019-04-16 05:38:45
回答 1查看 125关注 0票数 0

当运行显示具有子报表的crystal报表的应用程序时,系统会提示用户输入登录信息。

下面是我用来将登录信息传递给报表的代码。此代码在显示窗体时执行。我有一个测试vs2017应用程序,其中包含一个水晶报表查看器上的窗体。登录信息被传递,并且工作正常,直到我添加子报表。将子报表添加到我的现有报表后,系统会提示用户登录到数据库。输入正确的登录凭据后,将显示登录失败消息。无法运行该报告。报表从数据库的命令查询中获取数据。

代码语言:javascript
复制
    Sections crSections;
    ReportDocument crReportDocument, crSubreportDocument;
    SubreportObject crSubreportObject;
    ReportObjects crReportObjects;
    ConnectionInfo crConnectionInfo;
    Database crDatabase;
    Tables crTables;
    TableLogOnInfo crTableLogOnInfo;
    crReportDocument = new ReportDocument();
    crReportDocument.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CrystalReport3.rpt"));
    crDatabase = crReportDocument.Database;
    crTables = crDatabase.Tables;
    crConnectionInfo = new ConnectionInfo();
    crConnectionInfo.ServerName = "myservname";
    crConnectionInfo.DatabaseName = "mydatabasename";
    crConnectionInfo.UserID = "sa";
    crConnectionInfo.Password = "myusername";
    foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)
         {
         crTableLogOnInfo = aTable.LogOnInfo;
         crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
         aTable.ApplyLogOnInfo(crTableLogOnInfo);
         }
         // THIS STUFF HERE IS FOR REPORTS HAVING SUBREPORTS 
         // set the sections object to the current report's section 
         crSections = crReportDocument.ReportDefinition.Sections;
         // loop through all the sections to find all the report objects 
         foreach (Section crSection in crSections)
             {
             crReportObjects = crSection.ReportObjects;
             //loop through all the report objects in there to find all 
 subreports 
             foreach (ReportObject crReportObject in crReportObjects)
                 {
                 if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                 {
                     crSubreportObject = (SubreportObject)crReportObject;
                     //open the subreport object and logon as for the general report 
                     crSubreportDocument =                crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
                     crDatabase = crSubreportDocument.Database;
                     crTables = crDatabase.Tables;
                     foreach (CrystalDecisions.CrystalReports.Engine.Table aaTable in crTables)
                     {
                         crTableLogOnInfo = aaTable.LogOnInfo;
                         crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                         aaTable.ApplyLogOnInfo(crTableLogOnInfo);
                     }
                 }
            }
         }
    crystalReportViewer1.ReportSource = crReportDocument;
    crystalReportViewer1.Refresh();

我希望在我输入登录凭据时,运行报告时不提示用户。

EN

回答 1

Stack Overflow用户

发布于 2019-04-17 05:42:12

试试这个:Link

代码:

代码语言:javascript
复制
Sections crSections; 
ReportDocument crReportDocument, crSubreportDocument; 
SubreportObject crSubreportObject;
ReportObjects crReportObjects; 
ConnectionInfo crConnectionInfo; 
Database crDatabase; 
Tables crTables; 
TableLogOnInfo crTableLogOnInfo; 
crReportDocument = new ReportDocument();
crReportDocument.Load("c:\\reports\\Homes.rpt",CrystalDecisions.Shared.
OpenReportMethod.OpenReportByTempCopy); 
crDatabase = crReportDocument.Database; 
crTables = crDatabase.Tables; 
crConnectionInfo = new ConnectionInfo(); 
crConnectionInfo.ServerName = "DSNName Or Server Name"; 
crConnectionInfo.DatabaseName = "HopeAndHome";
crConnectionInfo.UserID = "sa"; 
crConnectionInfo.Password = "password"; 
foreach (Section crSection in crSections)
{
    crReportObjects = crSection.ReportObjects;
    //loop through all the report objects in there to find all subreports 
    foreach (ReportObject crReportObject in crReportObjects)
    {
        if (crReportObject.Kind == ReportObjectKind.SubreportObject)
        {
            crSubreportObject = (SubreportObject)crReportObject;
            //open the subreport object and logon as for the general report 
            crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
            crDatabase = crSubreportDocument.Database;
            crTables = crDatabase.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in crTables)
            {
                crTableLogOnInfo = aTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                aTable.ApplyLogOnInfo(crTableLogOnInfo);
            }
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55697581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档