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

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

在后台:

 

    protected void Page_Load(object sender, EventArgs e)
    {
        BindReport();
    }

    private void BindReport()
    {
        DataSet dsCryShui = new DataSet();
        TicOA.BLL.SF_SHUI ShuiBll = new TicOA.BLL.SF_SHUI();

        dsCryShui = dsCryShui = ShuiBll.GetListShuiAndShuiSys("");
        ReportDocument redoc = new ReportDocument();

        string reportLocalPath = "/CrystalReportShui.rpt";

        //获取程序根目录
        string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());
        //转换成绝对路径
        string reportPath = tmpRootDir + reportLocalPath.Replace(@"/", @"/");

        //读取Report
        redoc.Load(reportPath);

        redoc.SetDataSource(dsCryShui);

        #region 设置缺省的数据库连接属性(这样每次都不需要填写登录信息)
        TableLogOnInfo logOnInfo = new TableLogOnInfo();

        //从web.config中获取logOnInfo参数信息
        string ServerName, DatabaseName, UserID, Password;
        //获取ServerName
        ServerName = System.Configuration.ConfigurationManager.AppSettings["ServerName"];
        //获取DatabaseName
        DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"];
        //获取UserId
        UserID = System.Configuration.ConfigurationManager.AppSettings["UserID"];
        //获取password
        Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
        //设置logOnInfo参数
        logOnInfo.ConnectionInfo.ServerName = ServerName;
        logOnInfo.ConnectionInfo.DatabaseName = DatabaseName;
        logOnInfo.ConnectionInfo.UserID = UserID;
        logOnInfo.ConnectionInfo.Password = Password;

        redoc.Database.Tables[0].ApplyLogOnInfo(logOnInfo);

        #endregion

        this.CrystalReportShui.ReportSource = redoc;

        this.CrystalReportShui.HasCrystalLogo = false;

       
        }

 

在前台: <CR:CrystalReportViewer ID="CrystalReportShui" runat="server" AutoDataBind="true"
            Width="100%" Height="100%" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值