1.建立数据源dataset.xsd,在此文件中点右键,在弹出菜单中添加表datatable(表名可以随意),在表中添加列,列名要和通过SQL取得的列名要一致。
2. 通过添加新项目中的Report,添加报表Report1.rdlc,在工具箱中拖个表进去。从网站数据源中选中刚才建立的数据源中把各个列拖到表的字段里面就可以了。
3.往aspx页面中拖个microsftReportViewer,选择报表数据源report1.rdlc,设置好后会产生一个报表数据源ID和NAME,
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="DataSet1_t1" />
</DataSources>
</LocalReport>
4.后台代码
ds为dataset
rv.LocalReport.DataSources.Clear()
rv.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("DataSet1_t1", ds))
rv.LocalReport.Refresh()
其中第一个参数dataset1_t1要和报表数据源的name 相同。