鉴于机房合作时,自己在报表的使用有很多困惑,最近几天又有几个同学提出了同样的问题,写下本篇博文,希望以后可以帮到同学们。
1.新建报表
右击类库——添加——新建项——Reporting——报表
2.设计报表
3.详细配置
确定——下一步——下一步——
将报表的表格内容补充完整(第一行自己填写,第二行选择)
4.将控件与报表结合
5.添加代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Report
{
public partial class frmReport : Form
{
public frmReport()
{
InitializeComponent();
}
//参数类型根据需要自己定义,可以直接将参数定义为datetime类型
private string startDate = (new DateTime()).ToString();
private string endDate = (new DateTime()).ToString();
private void frmReport_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“ReportDataSet.T_Account”中。您可以根据需要移动或删除它。
//参数很重要,一定要把参数(startDate,endDate)写进来
this.T_AccountTableAdapter.Fill(this.ReportDataSet.T_Account, startDate.Trim(), endDate.Trim());
this.rptWeek.RefreshReport(); //刷新报表
}
private void btnRefresh_Click(object sender, EventArgs e)
{
//获得控件的值
startDate = dtpStartDate.Value.ToString();
endDate = dtpEndDate.Value.ToString();
this.T_AccountTableAdapter.Fill(this.ReportDataSet.T_Account, startDate.Trim(), endDate.Trim());
this.rptWeek.RefreshReport();
}
}
}
6.结果
果然自己总结一遍,清楚的不清楚的都清楚了,所以及时总结很重要。。。