最近在看报表这一块,在网上找到的大都是连接数据库的,对于自定义的DataTable数据没有详细的连接说明,经过一番寻找,总结一下大概方法,大神请直接无视
1、添加一个数据集

点确定后界面如下

在空白处右键

修改名称

添加行

重命名行

表效果

2、添加报表

确定后出现下面界面

然后添加资料数据源

点击新增,选择资料集,出现下面界面

输入名称为message,资料来源选择DataSet1,也就是你创建的DataSet1文件,资料集选择mytable,点击确定

然后在工具栏里拉一个资料表到报表上,然后如下

再如下

保存,报表完成,
下面搞窗体,拉一个ReportViewer控件到窗体上,

如果工具箱内找不到的话就自己添加进来一个,如下

然后在窗体的load事件里写代码 如下
1 DataTable dt = new DataTable();
2 dt.Columns.Add(new DataColumn("row1", typeof(string)));
3 dt.Columns.Add(new DataColumn("row2", typeof(string)));
4 for (int i = 0; i < 6; i++)
5 {
6 DataRow dr = dt.NewRow();
7 dr[0] = "a";
8 dr[1] = "b";
9 dt.Rows.Add(dr);
10 }
11 reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\Report1.rdlc";
12 //指定数据集,数据集名称后为表,不是DataSet类型的数据集
13 this.reportViewer1.LocalReport.DataSources.Clear();
14 this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("message", dt));
//在vs2005中没有找到重命名为messge的方法,这里这样写
// this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_mytable",dt));
15 //显示报表
16 this.reportViewer1.RefreshReport();
运行一下看看

注意:
第2和3行的列名要和数据集DataSet1里的列名一致
第11行的文件名要和你添加的报表文件名一致,路径要正确
第14行的message要和报表里的那个数据集的名称对应