Crystal报表和参数通过查询字符串

时间:2016-03-14 16:42:09

标签: c# asp.net crystal-reports

这是我的html:

<CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" AutoDataBind="true" />

这是加载代码:

ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(Server.MapPath("/reports/Mat-new.rpt"));


cryRpt.SetParameterValue("PO", Request.QueryString["po"]);
cryRpt.SetParameterValue("MR", Request.QueryString["mr"]);

CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();

var mytableloginfos = new TableLogOnInfos();
var myConnectionInfo = new ConnectionInfo();

mytableloginfos = CrystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
{
    myTableLogOnInfo.ConnectionInfo = myConnectionInfo;
}

myConnectionInfo.ServerName = "opl";
myConnectionInfo.DatabaseName = "FIL";
myConnectionInfo.UserID = "rep";
myConnectionInfo.Password = "rep";

对于我的生命,不能让参数通过。 知道如何让这个工作吗?

2 个答案:

答案 0 :(得分:2)

试试这个:

private void PassParameters()
{
 string po =  Request.QueryString["po"];
 string mr = Request.QueryString["mr"]

 ParameterValues ppo = new ParameterValues();
 ParameterValues pmr = new ParameterValues();

 ppo.AddValue(po);
 pmr.AddValue(mr);


 foreach (ParameterField field in cryRpt.ParameterFields)
 {
   if (string.Compare(field.Name.TrimStart('@'), "PO", true) == 0)
      field.CurrentValues = ppo;

   if (string.Compare(field.Name.TrimStart('@'), "MR", true) == 0)
      field.CurrentValues = pmr;

  }

答案 1 :(得分:0)

试试这个:

CrystalReportViewer1.ReportDocument.SetParameterValue("PO", Request.QueryString["po"]);
CrystalReportViewer1.ReportDocument.SetParameterValue("MR", Request.QueryString["mr"]);