1.在解决方案中添加新项目数据集-mydbDataSet.xsd,在数据集里添加所要用到的表或根据需要制作新表。
2.在设计页面中拉入一个MicrosoftReportViewer,设计新报表,按照报表向导根据自己的需要选择报表的数据源和数据项,完成新报表report1.rdlc的制作。在源码中如下(“考核成绩”为数据集中的一个表)
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"
Font-Size="8pt" Height="400px" Width="930px">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="mydbDataSet_考核成绩" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
3.进入代码页面
string strsql = "select * from XX where XX";
SqlDataAdapter da = new SqlDataAdapter(strsql, Connection);
DataSet dsrp = new DataSet();
da.Fill(dsrp, "考核成绩");
ReportDataSource reportDataSource1 = new ReportDataSource("mydbDataSet_考核成绩", dsrp.Tables["考核成绩"]);
ReportViewer1.LocalReport.ReportPath = MapPath("Report1.rdlc");
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(reportDataSource1);
ReportViewer1.LocalReport.Refresh();
4.注意事项
(1)注意源码中和代码中名字的一致
(2)在report1中如果要制作图表的话,确保数据类型是int或float
(3)报表生成还是挺好看的