///<summary> ///功能:拉模式提取水晶报表 ///个人主页:http://www.dzend.com/ ///</summary> ///<param name="sender"></param> ///<param name="e"></param> /// public int view_report(CrystalReportViewer CrystalReportViewer1, string file_name, string report_sql) { // CrystalReport.rpt是水晶报表文件的名称;CrystalReportSource1是从工具箱加到页面上的水晶报表数据源对像。 ExcuteDataTable(dt_report, report_sql, CommandType.Text); try { CrystalReportSource cs = new CrystalReportSource(); cs.ReportDocument.Load(file_name); cs.ReportDocument.SetDataSource(dt_report); cs.DataBind(); for (int i = 0; i < cs.ReportDocument.ParameterFields.Count; i++) { string ls_part = cs.ReportDocument.ParameterFields[i].Name; } CrystalReportViewer1.ReportSource = cs; CrystalReportViewer1.DataBind(); return(1); } catch (Exception e) { return(-1); } }
protected void Page_Load(object sender, EventArgs e) { var fileName = Request.QueryString["fileName"]; var filePath = String.Format("{0}\\{1}", Server.MapPath("~/Reports"), fileName); var fileInfo = new FileInfo(filePath); if (fileInfo.Exists == false) { ReturnErrorStatusAndShowMessage(fileName); return; } var connectionInfo = GetConnectionInfo(); CrystalDecisions.Web.Report webReport = new CrystalDecisions.Web.Report(); webReport.FileName = filePath; CrystalReportSource.Report = webReport; SetDBLogonForReport(connectionInfo, CrystalReportSource.ReportDocument); CrystalReportViewer.Error += new CrystalDecisions.Web.ErrorEventHandler(delegate(Object o, CrystalDecisions.Web.ErrorEventArgs errorArgs) { //ignore missing parameters error (not an error) if (!errorArgs.ErrorMessage.Contains("Missing parameter values")) { ShowFeaturedText(String.Format("Error {0}", errorArgs.ErrorMessage)); } }); CrystalReportViewer.DataBind(); CrystalReportViewer.RefreshReport(); }