水晶报表已经名声在外,但是这里我们使用VS2010中自带的rdlc报表。
第一步,创建数据集,并定义数据集
第二步,创建rdlc报表
第三步,创建ReportView
第四步,加载数据
String sql = "exec dbo.hsj_projectcostbaojia @headerId";
FunctionLib.openDatabase();
SqlDataAdapter adapter;
adapter = new SqlDataAdapter(sql, FunctionLib.Conn);
adapter.SelectCommand.Parameters.Clear();
adapter.SelectCommand.Parameters.AddWithValue("@headerId", headerId);
adapter.Fill(dtDgvProduct);
this.reportViewer1.LocalReport.DisplayName = "项目预算成本表";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dtDgvProduct));
this.reportViewer1.RefreshReport();