水晶报表取消输入密码最后测试结果

哈哈,找了很多资料终于解决了。

//添加引用

using CrystalDecisions.Shared ;//负责解释TableLogOnInfo类

using CrystalDecisions.CrystalReports .Engine ;//负责解释ReportDocument类private void Page_Load(object sender, System.EventArgs e)

//然后在水晶报表的Load事件中使用以下代码

private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            TableLogOnInfo logOnInfo = new TableLogOnInfo();
            //这里必须事先申明一个ReportDocument对象 Report,同时加载数据报表
            ReportDocument oRpt = new ReportDocument();
            oRpt.Load("D:\C#\InformationReport\InformationReport\InformationOfTender.rpt");//这里要修改为你自己的正确位置

            //建立安全信息
            //受密码保护的 Microsoft Access 和 Paradox 等 PC 数据库也使用该方法,但 LogOnInfo.ServerName //和 LogOnInfo.DatabaseName 要保留为空
            logOnInfo.ConnectionInfo.ServerName = "LENOVO-PC\SQLEXPRESS";
            logOnInfo.ConnectionInfo.DatabaseName = "YSZL";
            logOnInfo.ConnectionInfo.UserID = "sa";
            logOnInfo.ConnectionInfo.Password = "123456";

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

            //建立.rpt文件与CryStalReportviewer文件之间的连接
            crystalReportViewer1.ReportSource = oRpt;            
        }

  这样就不会提示密码错误了。感谢http://www.cnblogs.com/cailinaaa/archive/2008/12/27/1363759.html的分享,另外还有一些资料

趁年轻努力提高自己
原文地址:https://www.cnblogs.com/chinatrust/p/4090551.html