水晶报表子报表如何绑定数据源。。。。
主报表 :aimr181_2_std.rpt
子报表 :
主报表数据源:aimr181.XML
子报表数据源:aimjr181_sub1.XML
我拖了 CrystalReportViewer和CrystalReportSource控件到aspx上
后台代码:
CrystalReportViewer1.RefreshReport();
CrystalReportSource1.ReportDocument.Load(@"F:\aimr181\2\aimr181_2_std.rpt");
string oconn = "Data Source=toptest;user=ds7;password=ds7;";
DataSet ds = new DataSet();
OracleConnection ocnn = new OracleConnection(oconn);
OracleCommand ocmd = new OracleCommand();
ocmd.CommandType = CommandType.Text;
ocmd.Connection = ocnn;
OracleDataAdapter oda = new OracleDataAdapter();
oda.SelectCommand = ocmd;
string l_sql = "SELECT img01,img02,SUM(img10) FROM img_file GROUP BY img01,img02 ";
ocmd.CommandText = l_sql;
oda.Fill(ds, "img_file");
SubreportObject oSubreport1 = CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Subreport1"] as SubreportObject;
ReportDocument oSub1 = oSubreport1.OpenSubreport("aimr181_sub1");
oSub1.SetDataSource(ds.Tables["img_file"]);
l_sql = "SELECT ima01,ima02,ima021,ima05,ima06,ima07,ima08,ima37 FROM ima_file WHERE rownum < 50 ";
ocmd.CommandText = l_sql;
oda.Fill(ds, "ima_file");
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables["ima_file"]);
这个怎么子报表没有加载出来。
------解决方案--------------------
可以稍微封装一下
oda = new OracleDataAdapter(select * from c, ocnn);
oda.Fill(ds);
rd.Subreports[l_count].SetDataSource(ds.Tables[0]);
这三句封装成一句,减少点代码量。
别的方法也都不太简便。