经过几番周折,终于结合网上和自己的理解,通过参数字段方法传递了我要显示的值了!实在是很高兴,因为这是进步,还要努力,下面把这段自己写的代码奉献给大家分享:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared ;//负责解释TableLogOnInfo类
using CrystalDecisions.CrystalReports.Engine ;//负责解释ReportDocument类
public partial class Report_ReportContent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//CrystalReportViewer1.te
TableLogOnInfo logOnInfo = new TableLogOnInfo ();
//这里必须事先申明一个ReportDocument对象 Report,同时加载数据报表
ReportDocument oRpt = new ReportDocument();
//获取.rpt文件真实路径
string path1,path2;
path1 = Server.MapPath(".");
path2 = path1 + "/CrystalReport.rpt";
//Response.Write(path2);
//Response.End();
oRpt.Load(path2);
//从web.config中获取logOnInfo参数信息
string a,b,c,d;
//获取ServerName
a=System.Configuration .ConfigurationSettings .AppSettings ["servername"];
//获取DatabaseName
b=System.Configuration .ConfigurationSettings .AppSettings ["database"];
//获取UserId
c=System.Configuration .ConfigurationSettings .AppSettings ["userid"];
//获取password
d=System.Configuration .ConfigurationSettings .AppSettings ["pass"];
//设置logOnInfo参数
logOnInfo.ConnectionInfo.ServerName = a;
logOnInfo.ConnectionInfo.DatabaseName = b;
logOnInfo.ConnectionInfo.UserID = c;
logOnInfo.ConnectionInfo.Password = d;
oRpt.Database .Tables [0].ApplyLogOnInfo (logOnInfo);
//建立.rpt文件与CryStalReportviewer文件之间的连接
CrystalReportViewer1.ReportSource = oRpt;
//查看器控件所需的变量。
ParameterValues paramValues = new ParameterValues();
ParameterDiscreteValue paradisvalues = new ParameterDiscreteValue();
paradisvalues.Value = "测试文字1---显示为正常";
paramValues.Add(paradisvalues);
oRpt.DataDefinition.ParameterFields[0].ApplyCurrentValues(paramValues);
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared ;//负责解释TableLogOnInfo类
using CrystalDecisions.CrystalReports.Engine ;//负责解释ReportDocument类
public partial class Report_ReportContent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//CrystalReportViewer1.te
TableLogOnInfo logOnInfo = new TableLogOnInfo ();
//这里必须事先申明一个ReportDocument对象 Report,同时加载数据报表
ReportDocument oRpt = new ReportDocument();
//获取.rpt文件真实路径
string path1,path2;
path1 = Server.MapPath(".");
path2 = path1 + "/CrystalReport.rpt";
//Response.Write(path2);
//Response.End();
oRpt.Load(path2);
//从web.config中获取logOnInfo参数信息
string a,b,c,d;
//获取ServerName
a=System.Configuration .ConfigurationSettings .AppSettings ["servername"];
//获取DatabaseName
b=System.Configuration .ConfigurationSettings .AppSettings ["database"];
//获取UserId
c=System.Configuration .ConfigurationSettings .AppSettings ["userid"];
//获取password
d=System.Configuration .ConfigurationSettings .AppSettings ["pass"];
//设置logOnInfo参数
logOnInfo.ConnectionInfo.ServerName = a;
logOnInfo.ConnectionInfo.DatabaseName = b;
logOnInfo.ConnectionInfo.UserID = c;
logOnInfo.ConnectionInfo.Password = d;
oRpt.Database .Tables [0].ApplyLogOnInfo (logOnInfo);
//建立.rpt文件与CryStalReportviewer文件之间的连接
CrystalReportViewer1.ReportSource = oRpt;
//查看器控件所需的变量。
ParameterValues paramValues = new ParameterValues();
ParameterDiscreteValue paradisvalues = new ParameterDiscreteValue();
paradisvalues.Value = "测试文字1---显示为正常";
paramValues.Add(paradisvalues);
oRpt.DataDefinition.ParameterFields[0].ApplyCurrentValues(paramValues);
}
}
本文介绍了一种在水晶报表(Crystal Report)中通过参数字段方法成功传递显示值的方法,并详细展示了如何设置连接信息及应用参数的具体步骤。
183

被折叠的 条评论
为什么被折叠?



