如果要用水晶报表设计需要向下穿透的主从报表时好像不容易,今天找了一些资料,水晶报表向下钻取的功能很有限,从表需要连接的关键字必须在主表中,如果要实现在主报表的某条数据点击后穿透到从表对应该纪录的子表信息,而子表信息需要其他参数(主表中没有)才能组织报表数据 。还好可以用推模式自己组织数据。
例子:
SqlConnection conn = new SqlConnection(@"Data Source=CNCTU006630W/SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True;Pooling=False;");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from mytable ",conn);
da.Fill(ds,"mytable");
da = new SqlDataAdapter("select * from mytable2 ",conn);
da.Fill(ds,"mytable2");
ReportDocument oRpt = new ReportDocument();
oRpt.Load(Server.MapPath("CrystalReport.rpt"));
oRpt.SetDataSource(ds);
ReportDocument suboRpt = oRpt.OpenSubreport("mysub01");
suboRpt.SetDataSource(ds);
CrystalReportViewer1.ReportSource = oRpt;
CrystalReportViewer1.DataBind();