水晶报表自定义参数传递个人示例代码

经过几番周折,终于结合网上和自己的理解,通过参数字段方法传递了我要显示的值了!实在是很高兴,因为这是进步,还要努力,下面把这段自己写的代码奉献给大家分享:

 

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);
    }
}
终于在我要的水晶报表里显示了这些字“测试文字1---显示为正常”!我一下子兴奋了!继续研究,项目需要这个,现在自己在做视图,和动态参数查询新的报表!期待尽快解决!
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值