以下為aspx.cs程式,page load的時候傳入ProductID給CrystalReport
當然在CrystalReport.rpt裡面要設定"參數欄位"
然後在"資料錄選擇"加入條件式
如:{Risk.ProjectID} = {?ProjectID}
aspx.cs程式:
//load crystal report
this.CrystalReportSource1.Report.FileName = Server.MapPath("RiskCrystalReport.rpt");
//設定資料庫連線訊息
TableLogOnInfo dbConn = new TableLogOnInfo();
dbConn.ConnectionInfo.DatabaseName = "DB";
dbConn.ConnectionInfo.ServerName = "XX.XX.XX.XX";
dbConn.ConnectionInfo.UserID = "User";
dbConn.ConnectionInfo.Password = "Password";
this.CrystalReportSource1.ReportDocument.Database.Tables[0].ApplyLogOnInfo(dbConn);
//load param
CrystalDecisions.Web.Parameter param = new CrystalDecisions.Web.Parameter();
param.Name = "ProductID";
param.DefaultValue = "1";
//add param
this.CrystalReportSource1.Report.Parameters.Add(param);
//bind
this.CrystalReportViewer1.ReportSourceID = this.CrystalReportSource1.ID;
this.CrystalReportViewer1.DataBind();
當然在CrystalReport.rpt裡面要設定"參數欄位"
然後在"資料錄選擇"加入條件式
如:{Risk.ProjectID} = {?ProjectID}
aspx.cs程式:
//load crystal report
this.CrystalReportSource1.Report.FileName = Server.MapPath("RiskCrystalReport.rpt");
//設定資料庫連線訊息
TableLogOnInfo dbConn = new TableLogOnInfo();
dbConn.ConnectionInfo.DatabaseName = "DB";
dbConn.ConnectionInfo.ServerName = "XX.XX.XX.XX";
dbConn.ConnectionInfo.UserID = "User";
dbConn.ConnectionInfo.Password = "Password";
this.CrystalReportSource1.ReportDocument.Database.Tables[0].ApplyLogOnInfo(dbConn);
//load param
CrystalDecisions.Web.Parameter param = new CrystalDecisions.Web.Parameter();
param.Name = "ProductID";
param.DefaultValue = "1";
//add param
this.CrystalReportSource1.Report.Parameters.Add(param);
//bind
this.CrystalReportViewer1.ReportSourceID = this.CrystalReportSource1.ID;
this.CrystalReportViewer1.DataBind();
全站熱搜
留言列表