我在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
提前致谢
答案 0 :(得分: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;
希望这会对你有所帮助。!!!