从c#发送变量到晶体报告 [英] send variables to crystal report from 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["mPeriod"]);
string myYr = (String)(Session["mYear"]);
to the cyrstal report.
What is the procedure.
New to crystal report
protected void Page_Init(object sender, EventArgs e)
{
string myst1 = (String)(Session["myText"]);
string myst2 = (String)(Session["other"]);
string myPrd = (String)(Session["mPeriod"]);
string myYr = (String)(Session["mYear"]);
if (myst2 == "OTHER")
{
if (myst1 == "LOAN BALANCES - DFI")
{
reportDocum.Load(Server.MapPath("~/Reports/loan_portfolio_otherG.rpt"));
}
else
{
reportDocum.Load(Server.MapPath("~/Reports/loan_portfolio_other.rpt"));
}
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屋!