水晶报表中不需要填写登陆信息实现

来源:互联网 发布:log4cpp 网络传输 编辑:程序博客网 时间:2024/06/02 04:21

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;//负责解释ReportDocument类
using CrystalDecisions.Shared;//负责解释tableLogOninfo类
namespace WV
{
    public partial class reportFrame : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            login log = new login();
            DataSet ds = new DataSet();
            string strSql = string.Format(@"select a.customerid,a.name,a.sex,b.enddt from base_customers a join kqxt_leave b on a.customerid=b.customerid where  rownum<50");
            ds = log.Query(strSql);//获取数据源
            ReportDocument rd = new ReportDocument();
            //获取报表路径
            string reportPath = Server.MapPath("reportFolder/report.rpt");
            rd.Load(reportPath);
            rd.SetDataSource(ds);
            //添加登录信息
            TableLogOnInfo logOnInfo = new TableLogOnInfo();
            logOnInfo.ConnectionInfo.ServerName = "数据库名";
            logOnInfo.ConnectionInfo.DatabaseName = "";
            logOnInfo.ConnectionInfo.UserID = "用户名";
            logOnInfo.ConnectionInfo.Password = "密码";
            rd.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
           
            CrystalReportViewer1.ReportSource = rd;
        }
    }
}