日期:2014-05-18  浏览次数:20412 次

ASPNET如何制作水晶报表
希望高手发表意见。。以前没有做过这个水晶报表。。查了写资料,大多雷同。。代码也用不了。。

------解决方案--------------------
数据库连接类,需要在webconfig中设置好AppSettings["servername"],AppSettings["userid"],AppSettings["pass"]这三个数据库OLEDB的连接字符串. 
C# code
public class LoginCrystalReport
    {
        public void Login(CrystalDecisions.CrystalReports.Engine.ReportDocument report)
        {
            string servername, username, password;
            // t Database Logon to main report 
            servername = System.Configuration.ConfigurationSettings.AppSettings["servername"];
            username = System.Configuration.ConfigurationSettings.AppSettings["userid"];
            password = System.Configuration.ConfigurationSettings.AppSettings["pass"];
            foreach (CrystalDecisions.Shared.IConnectionInfo connection in report.DataSourceConnections)
            {
                if (connection.ServerName == servername)
                {
                    connection.SetLogon(username, password);
                }
            }
            // t Database Logon to subreport 
            foreach (CrystalDecisions.CrystalReports.Engine.ReportDocument subreport in report.Subreports)
            {
                foreach (CrystalDecisions.Shared.IConnectionInfo connection in subreport.DataSourceConnections)
                {
                    if (connection.ServerName == servername)
                    {
                        connection.SetLogon(username, password);
                    }
                }
            }
        }
    }