从c#发送变量到晶体报告 [英] send variables to crystal report from c#

查看:79
本文介绍了从c#发送变量到晶体报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要发送字符串变量



  string  myPrd = ( String )(会话[& quot; mPeriod& quot;]); 
string myYr =( String )(会话[& quot; mYear& quot;] );





到cyrstal报告。



什么是程序。



水晶报告新手



<前lang =c#> protected void Page_Init( object sender,EventArgs e)
{
string myst1 =( String )(会话[& quot; myText& ; QUOT;]);
string myst2 =( String )(会话[& quot; other& quot;] );

string myPrd =( String )(会话[& quot; mPeriod& amp; ; QUOT;]);
string myYr =( String )(会话[& quot; mYear& quot;] );


if (myst2 ==& quot; OTHER& quot;)
{
< span class =code-keyword> if (myst1 ==& quot; LOAN BALANCES - DFI& quot;)
{
reportDocum.Load(Server.MapPath(& quot) ;〜/报告/ loan_portfolio_otherG.rpt&安培; QUOT;));
}
else
{
reportDocum.Load(Server.MapPath(& quot;〜/ Reports / loan_portfolio_other)的.rpt&安培; QUOT;));
}

解决方案

请使用参数解决问题,例如



 ReportDocument myDataReport =  new  CrystalDecisions.CrystalReports.Engine.ReportDocument(); 
myDataReport.Load( @ C:\ _Reports\Report.rpt) ;

myDataReport.SetParameterValue( MyParameter1 Hello1);
myDataReport.SetParameterValue( MyParameter2 Hello2);
myDataReport.SetParameterValue( MyParameter3 Hello3);





这是短甜蜜的解决方案。但是,在此之后,您必须确保在Crystal Reports设计器中创建了类型为String的MyParameter1,MyParameter2和MyParameter3。



重要的是要提到你有在使用SetParameterValue设置参数之前加载报告。



如果参数的名称是MyParameter1,那么不要像这样在前面添加@:



myDataReport.SetParameterValue(@ MyParameter1,Hello1); //你的程序会崩溃。





希望这有助于你


Need to send the string variables

string myPrd = (String)(Session[&quot;mPeriod&quot;]);
                string myYr  = (String)(Session[&quot;mYear&quot;]);



to the cyrstal report.

What is the procedure.

New to crystal report

protected void Page_Init(object sender, EventArgs e)
      {
          string myst1 = (String)(Session[&quot;myText&quot;]);
          string myst2 = (String)(Session[&quot;other&quot;]);

          string myPrd = (String)(Session[&quot;mPeriod&quot;]);
          string myYr  = (String)(Session[&quot;mYear&quot;]);


          if (myst2 == &quot;OTHER&quot;)
          {
              if (myst1 == &quot;LOAN BALANCES - DFI&quot;)
              {
                  reportDocum.Load(Server.MapPath(&quot;~/Reports/loan_portfolio_otherG.rpt&quot;));
              }
              else
              {
                  reportDocum.Load(Server.MapPath(&quot;~/Reports/loan_portfolio_other.rpt&quot;));
              }

解决方案

Please use Parameter to solve the problem like

ReportDocument myDataReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
myDataReport.Load(@"C:\Reports\Report.rpt");

myDataReport.SetParameterValue("MyParameter1", "Hello1");
myDataReport.SetParameterValue("MyParameter2", "Hello2");
myDataReport.SetParameterValue("MyParameter3", "Hello3");



This is the short and sweet solution. But, following this, you have to make sure you have created MyParameter1, MyParameter2 and MyParameter3 of type String in the Crystal Reports Designer.

It's important to mention that you have to Load the report before setting your parameters with SetParameterValue.

If your parameter's name is MyParameter1, then don't add a @ in front like this :

myDataReport.SetParameterValue("@MyParameter1", "Hello1"); // Your program will crash.


Hope this helps you


这篇关于从c#发送变量到晶体报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆