【问题标题】:Crystal Report in ASP.Net passing parameter values and no valid report sourceASP.Net 中的 Crystal Report 传递参数值并且没有有效的报表源
【发布时间】:2012-09-05 04:56:37
【问题描述】:

在 ASP.Net 网页上显示 Crystal 报表时遇到问题。该网站只是一个内部网站,因此您会看到我已将文件路径编码到该网站中。我想我已经很接近让这个工作了,但我显然错过了一些东西。有人可以帮忙吗?

他是我的密码:

void BindReport()
{
    ReportDocument rd = new ReportDocument();

    //Report is saved on an external server which I have full access too
    rd.Load(@"\\MyServer\Reports\MyReport.rpt");
    rd.SetDatabaseLogon("UserName", "Password", "MyServer", "MyDatabase", true);
    //The Report has 2 parameter and links directly to a stored procedure on a SQL Server
    rd.SetParameterValue("@uspDateFrom", new DateTime(2012, 05, 01));
    rd.SetParameterValue("@uspDateTo", new DateTime(2012, 05, 31));
    CrystalReportViewer1.ReportSource = rd;
    CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
    CrystalReportViewer1.RefreshReport();
}

//I call my report on a button click
protected void buttonPreviewReport_Click(object sender, EventArgs e)
{
    BindReport();
}

当报告尝试运行时,我会弹出一个对话框,询问我的参数值,即使我已经传递了它们!?即使我在对话框提示中输入它们,我也会收到一条消息,指出没有可用的有效报告源。

有人有什么想法吗?

我正在使用 ASP.Net 4.0

提前致谢

【问题讨论】:

    标签: asp.net crystal-reports


    【解决方案1】:

    我在使用 Crystal Report 时遇到过同样的问题。

      ParameterFields paramFields = new ParameterFields();
    
      ParameterField paramField = new ParameterField();
    
      ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
    
      paramField.ParameterFieldName = "@examid";// This is how you can send Parameter Value to the Crystal Report
    
    
     // Set the first discrete value and pass it to the parameter.
       discreteVal.Value = ddlAllExam.SelectedValue;//Value from DropDown
    
       paramField.CurrentValues.Add(discreteVal);
    
       paramFields.Add(paramField);
    
       CrystalReportViewer1.ParameterFieldInfo = paramFields;
    
       string datasource = System.Configuration.ConfigurationManager.AppSettings["Data Source"].ToString();
    
       string Database = System.Configuration.ConfigurationManager.AppSettings["Database"].ToString();
    
       string Userid = System.Configuration.ConfigurationManager.AppSettings["Userid"].ToString();
    
       string Password = System.Configuration.ConfigurationManager.AppSettings["Password"].ToString();
    
        ReportDocument report = new ReportDocument();
    
        report.Load(Server.MapPath("~/Reports/AllExamReport.rpt"));//Here you can give the Path of external Server
    
        report.SetDatabaseLogon(Userid, Password, datasource, Database);
    
        CrystalReportViewer1.ReportSource = report;
    

    希望对你有帮助。!!!

    【讨论】:

      猜你喜欢
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多