所以我有一个.rpt文件,想要以网络形式显示水晶报告。
我将报表查看器拖到我的网络表单上,并在设计时设置其CrystalReportSource。
当我浏览页面时,它要求我输入一个sql密码并且已经填写了SQL服务器名称和用户。
如何在后面的代码中设置数据库连接并让页面显示报告而不提示输入SQL密码?
我应该生成一个数据集并将晶体报告查看器数据绑定到rpt文件和数据集吗?
答案 0 :(得分:2)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class crystal_report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void Page_Init(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
private void ConfigureCrystalReports()
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.DatabaseName = "PMIS";
connectionInfo.UserID = "PMIS_User";
connectionInfo.Password = "Welcome1";
SetDBLogonForReport(connectionInfo);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo) {
TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{
tableLogOnInfo.ConnectionInfo = connectionInfo;
}
}
}