1.添加引用在Demo檔案夾下面的FastReport.dll和FastReport.Web.dll
2.添加using FastReport;
using FastReport.Web;
3. 在Web頁面上拖拉FastReport到頁面,進入Design 視圖進行設計
4。 為FastReport添加 WebReport1_StartReport事件
/// <summary>
/// 得到資料
/// </summary>
/// <returns></returns>
public DataSet getData()
{
string con = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlConnection connection = new SqlConnection(con);
SqlCommand command = new SqlCommand("Select * from Manager",connection);
SqlDataAdapter sda = new SqlDataAdapter(command);
DataSet ds=new DataSet();
DataTable managerData = new DataTable();
managerData.TableName = "Manager";
sda.Fill(managerData);
ds.Tables.Add(managerData);
DataTable payrecord = new DataTable();
payrecord.TableName = "PayRecord";
SqlCommand command1 = new SqlCommand("select * from PayRecord", connection);
SqlDataAdapter sda1 = new SqlDataAdapter(command1);
sda1.Fill(payrecord);
ds.Tables.Add(payrecord);
return ds;
}
protected void WebReport1_StartReport(object sender, EventArgs e)
{
FastReport.Report report = this.WebReport1.Report;
report.Load(Server.MapPath("\\ReportTemplate\\demo.frx"));//載入模板
DataSet ds=this.getData();
report.RegisterData(ds);//註冊資料
}
5.為Table添加Table2_ManualBuild事件
private void Table2_ManualBuild(object sender, EventArgs e)
{
DataSourceBase source=Report.GetDataSource("Manager");
source.Init();
Table2.PrintRow(0);
Table2.PrintColumns();
while(source.HasMoreRows)
{
Table2.PrintRow(1);
Table2.PrintColumns();
source.Next();
}
} 體驗新版部落格