RDLC报表的使用

首先,下载reportviewer,下载地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=8A166CAC-758D-45C8-B637-DD7726E61367

安装过后,工具栏的报表里边,就有着个控件了。

然后的工作是,新建一个数据集,在数据集中新建表,添加新列,并设置列的类型,

下一步,就是新建一个报表文件,扩展名为rdlc

打开报表,在工具栏中拖放一个图表,将数据集中表里的相对应的字段拖到图表中。

报表跟数据集关联好之后,接下来的工作便是,向数据集中填充数据,并将rdlc报表绑定到reportviewer中

DataTable dt = newRentalCountDS().RentalCount_Table;  //初始化一个数据集中的表
for (int i = 0; i < RentalCountList.Count(); i++)  //循环遍历从数据库返回的数组RentalCountList
{
DataRow dr
= dt.NewRow();
dr[
"Counts"] = RentalCountList[i].Counts;
dr[
"CardType"] = RentalCountList[i].CardType;
dr[
"Date"] = RentalCountList[i].Date;
dr[
"OperType"] = RentalCountList[i].OperType;
dt.Rows.Add(dr);
}
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
this.reportViewer1.LocalReport.ReportPath = @"addin\RDLC\RentalCountsReport.rdlc"; //注意路径问题,如果出错,可以把报表的属性改为,可复制,内容
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("RentalCountDS_RentalCount_Table", dt));
this.reportViewer1.RefreshReport();

好了,基本上效果可以实现了。

有一点要注意,从数据库返回的字段名,应该和数据集中表中的字段名一致

posted @ 2011-03-15 18:33  陈帆  Views(2868)  Comments(0Edit  收藏  举报