日期:2014-05-20 浏览次数:20724 次
……
//ds中装的数据
string sql = "select * from Department,Class where Department.DepartNo=Class.DepartNo";
……
private void tsPrint_Click(object sender, EventArgs e)
{
rptClass r = new rptClass(); //rptClass是已经建好的班级信息的数据报表文件
r.SetDataSource(ds.Tables[0]); //断点测试后已经查看了ds不是空的,有所需要的数据
frmPrint p = new frmPrint(); //frmPrint窗体中已经放好了一个报表预览控件
p.crystalReportViewer1.ReportSource = r;
p.ShowDialog();
}
CrystalDecisions.CrystalReports.Engine.ReportDocument dcResult = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); //这个跟你rptClass不一样
dcResult.Load(Application.StartupPath + "\\crpYear.rpt"); //加载报表文件
dcResult.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = dcResult;