本文介绍了水晶报表无法获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是水晶报表的新手,我需要一些帮助:我已经通过以下两种方式设置了数据库登录"报告:

I'm new in crystal report I need some help:I have been set the report Database Logon in two ways as following:

第一个:rpt.SetDatabaseLogon(userId,userPassword);

1st: rpt.SetDatabaseLogon(userId, userPassword);

2nd:DatabaseLogOn(fullserverName,dBName,dBUser,userPassword);

2nd: DatabaseLogOn(fullserverName, dBName, dBUser, userPassword);

第一种方法运作良好,但出于某些原因,我需要将其更改为第二种方法,但是不幸的是,它不起作用,我也不知道原因:

the first way is working well but I need to change it to the second one for some reasons butUnfortunately it's not working and I don't know the reason:

public void DatabaseLogOn(string serverstring, string databasestring, string useridstring, string passwordstring)
            {
                var crConnectionInfo = new ConnectionInfo();
                crConnectionInfo.ServerName = serverstring;
                crConnectionInfo.DatabaseName = databasestring ;
                crConnectionInfo.UserID = useridstring ;
                crConnectionInfo.Password = passwordstring ;
                crConnectionInfo.IntegratedSecurity = true;
                var crTableLogonInfo = new TableLogOnInfo();
                Tables CrTables;
                CrTables = rpt.Database.Tables;
                foreach (Table crTable in CrTables)
                {
                    crTableLogonInfo = crTable.LogOnInfo;
                    crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                    crTable.ApplyLogOnInfo(crTableLogonInfo);

                }

            Sections CrSections = rpt.ReportDefinition.Sections;
            // loop through all the sections to find all the report objects
            foreach (Section CrSection in CrSections)
            {
                ReportObjects 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)
                    {
                        SubreportObject CrSubreportObject = (SubreportObject)CrReportObject;
                        //open the subreport object and logon as for the general report
                        ReportDocument CrSubreportDocument =      CrSubreportObject.OpenSubreport(CrSubreportObject.SubreportName);
                        CrTables = CrSubreportDocument.Database.Tables;
                        foreach (Table aTable in CrTables)
                        {
                            crTableLogonInfo = aTable.LogOnInfo;
                            crTableLogonInfo.ConnectionInfo = crConnectionInfo;
                            aTable.ApplyLogOnInfo(crTableLogonInfo);

                        }
                    }
                }
            }


        }

可以有任何帮助

推荐答案

您是否已签出此?它几乎与您的相同,并且帖子的答案表明结构稍有更改.

Have you checked out this post? It is almost identical to yours and the answer to the post suggests slight changes to the structure.

这篇关于水晶报表无法获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 19:29