CrystalReportViewer无法自动识别参数值 [英] CrystalReportViewer not recognizing parameters values automatically
本文介绍了CrystalReportViewer无法自动识别参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的价值观没有自动传递,任何想法为什么?
加载代码:
My values arent getting pass automatically, any idea why?
On load code:
//login so users wont have to enter user/pass all the time
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load(Server.MapPath("~/reports/RecReport.rpt"));
crConnectionInfo.ServerName = "e40";
crConnectionInfo.DatabaseName = " ";
crConnectionInfo.UserID = "usr";
crConnectionInfo.Password = "pas";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportSource1.ReportDocument.SetParameterValue(0, Request.QueryString["PONU"]);
CrystalReportSource1.ReportDocument.SetParameterValue(1, Request.QueryString["MRNU"]);
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
它要求我在代码运行后再次输入值,我错过了什么?
It asks me to enter the values again after the code run, am i missing anything?
推荐答案
设置报告源后,您无需刷新报告查看器。
删除行
You do not need to refresh the Report viewer after setting the report source.
Remove the line
CrystalReportViewer1.RefreshReport();
我加载报告的方式如下 - 无论参数是Crystal还是Crystal,这总是适用于我由于底层存储过程;
The way I load a report is as follows - this always works for me regardless if the parameters are Crystal or due to an underlying stored procedure;
using(ReportDocument crReport = new ReportDocument())
{
crReport.Load("Path and file name");
if(crReport.DataDefintion.ParameterFields.Count > 0)
{
foreach(ParameterFieldDefintion crDef in crReport.DataDefinition.ParameterFields)
{
// check the parameter is not in a Sub Report
if(crDef.ReportName == string.Empty)
{
crReport.SetParameterValue(crDef.ParameterFieldName, "myvalue");
}
}
}
ConnectionInfo crConn = new ConnectionInfo();
crConn.ServerName = "myServer";
crConn.DatabaseName = "myDbName";
crConn.UserID = "myUserName";
crConn.Password = "myPassword";
Tables crTables = crReport.Database.Tables;
// I have had problems using the tables collection so instead I use an enumerator
for(int i = 0; i < crTables.Count; i++)
{
Table crTable = crTables[i];
TableLogOnInfo tblInfo = crTable.LogOnInfo;
tblInfo.ConnectionInfo = crConn;
crTable.ApplyLogOnInfo(tblInfo);
}
if(crReport.Subreports.Count > 0)
{
for(int i = 0; i < crReports.Subreports.Count; i++)
{
using(ReportDocument crSub = crReport.OpenSubReport(crReport.Subreports[i].Name)
{
Tables crSubTables = crSub.Database.Tables;
for (int ii = 0; ii < crSubTables.Count; ii++)
{
Table crSubTable = crSubTables[i];
TableLogOnInfo tblSInfo = crSubTable.LogOnInfo;
tblSInfo.ConnectionInfo = crConn;
crSubTable.ApplyLogOnInfo(tblSInfo);
}
crSub.Close();
}
}
}
}
this.crystalReportViewMain.ReportSource = crReport;
// this.crystalReportViewMain.RefreshReport();
如果我取消注释最后一行,我会得到你描述的行为,然后报告会提示我重新输入参数值
真的希望这会对你有所帮助
亲切的问候
If I uncomment the last line I get the behavior you describe in that the Report then prompts me to re-enter the parameter values
Really hope this helps you
Kind Regards
这篇关于CrystalReportViewer无法自动识别参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文