1

我无法在 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

提前致谢

4

1 回答 1

0

我在使用 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;

希望对你有帮助。!!!

于 2012-09-12T08:06:15.507 回答