首页 > 解决方案 > 钻取 rdlc 报告未加载

问题描述

我在 MVC5 Visual Studio 2015 工作。我想创建一个父子报表,父报表加载而子报表不加载。如果我单击父报表上的参数字段,子报表将像要加载一样执行,但会弹出错误“未为 DataSet1 提供数据源”下面是我的代码示例:

System.Data.DataSet ds = new System.Data.DataSet();

public ActionResult ReportStudClass()
        {
            //string CommandText = ("select Se.Session_Name,Tm.Term_Name,CLN.CL_Name,St.Student_Classid,St.RegistrationNo from Student_Class St " 
            //   + " inner join Session Se ON St.Sessionid = Se.Sessionid inner join Term Tm ON St.Termid = Tm.Termid inner join Class_Name CLN "
            //   + " ON St.Class_Nameid = CLN.Class_Nameid where St.Sessionid = @SessionParam and St.Termid = @TermParam and St.Class_Nameid = @ClassParam ");

            // Set the processing mode for the ReportViewer to Local
            //  ReportViewer reportViewer = new ReportViewer();
            //  reportViewer.ProcessingMode = ProcessingMode.Local;
            //  LocalReport localReport = reportViewer.LocalReport;
            //  localReport.ReportPath = "Report1.rdlc";
            //  System.Data.DataSet dataset = new System.Data.DataSet("Report1");

            //  GetBill_Indv(ref dataset);
            //  ReportDataSource dsBPIndvRpt = new ReportDataSource();
            ////  ReportDataSource source = new ReportDataSource("DataSet1", dataset.Tables[0]);
            //  dsBPIndvRpt.Name = "BPIndvRpt";
            //  dsBPIndvRpt.Value = dataset.Tables["BPIndvRpt"];
            //  dsBPIndvRpt.DataMember = "DataSet1";
            //  // DataSet ds = new DataSet("Sales Order Detail");
            //  // string salesOrderNumber = "SO43661";
            // localReport.DataSources.Add( dsBPIndvRpt);


            //  ViewBag.ReportViewer = reportViewer;
            //  return View();

            ReportViewer reportViewer = new ReportViewer();
            reportViewer.ProcessingMode = ProcessingMode.Local;
            reportViewer.ShowPrintButton = true;
            reportViewer.SizeToReportContent = true;
            reportViewer.Width = Unit.Percentage(900);
            reportViewer.Height = Unit.Percentage(900);

            string sconn = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinanceDbContext"].ConnectionString;
            var conn = new SqlConnection(sconn);
            //DataTable dtbl = new DataTable("DataTable1");
            SqlDataAdapter adp = new SqlDataAdapter();
            adp.SelectCommand = new SqlCommand();
            adp.SelectCommand.Connection = conn;
            adp.SelectCommand.CommandText = "Bill_Prep_IndvRepChildUF";
            adp.SelectCommand.CommandType = CommandType.StoredProcedure;
            //adp.Fill(ds);

            // ReportDataSource source = new ReportDataSource("DataSet1", ds.Tables[0]);
            // SqlDataAdapter adp = new SqlDataAdapter("select Bill_Prep_Indvid,Bill_Prepid,Student_Classid,RegistrationNo,Class_Nameid, Sessionid,Termid,Bill_Typeid,Description,Bill_Percent, Bill_Amount-(Bill_Amount*Bill_Percent) as BillAmount  from Bill_Prep_Indv", conn);
            //  SqlDataAdapter adp = new SqlDataAdapter("select Bill_Prep_Indvid,Bill_Prepid,Student_Classid,RegistrationNo,"+
            //   "  Class_Nameid, Sessionid,Termid,Bill_Typeid,Description,Bill_Percent, Bill_Amount from Bill_Prep_Indv", conn);
            //SqlCommand comm1 = new SqlCommand("Select * from Session", conn);
            //SqlDataAdapter adp = new SqlDataAdapter("Select * from Student_Class", conn);
            // SqlDataAdapter adp = new SqlDataAdapter("Select * from Bill_Prep", conn);
            //SqlDataAdapter adp = new SqlDataAdapter("Select * from Bill_Prep_Indv", conn);
            //SqlCommand cmd = new SqlCommand("Bill_Prep_IndvRep");
            // SqlDataAdapter adp = new SqlDataAdapter(cmd);

            adp.SelectCommand.CommandTimeout = 0;
            adp.Fill(ds);
            //adp.Fill(ds, "Student_Class");
            // adp.Fill(ds, "Bill_Prep_Indv");
            // adp.Fill(ds, "Bill_Prep_Indv");
            //Add parameters table
            //SqlCommand comm1 = new SqlCommand("Select * from Session", conn);
            //ds.Tables.Add("Se");
            //adp.SelectCommand = comm1;
            //adp.Fill(ds.Tables["Se"]);

            //SqlCommand comm2 = new SqlCommand("Select * from Term", conn);
            //ds.Tables.Add("Tm");
            //adp.SelectCommand = comm2;
            //adp.Fill(ds.Tables["Tm"]);


            //  adp.SelectCommand = cmd //cmd represent query parameter or sqlcommand query
            reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Report\Report5.rdlc";
            reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", ds.Tables[0]));

           // call drillthrough report
            reportViewer.Drillthrough += new DrillthroughEventHandler(reportViewer_Drillthrough);

            // reportViewer.LocalReport.DataSources.Clear();
            //  reportViewer.LocalReport.DataSources.Add(source);
            //  reportViewer.LocalReport.Refresh();
            //   Cache["DsChild"] = "Dataset2";
            ViewBag.ReportViewer = reportViewer;



            return View();
        }
private DataTable GetBillReport( int Sessionid)
        {
            System.Data.DataSet ds2 = new System.Data.DataSet();

            try
            {

                //DataTable dt = new DataTable();
                //DataTable dtSe = new DataTable();
                //DataTable dtTm = new DataTable();
                //DataTable dtBt = new DataTable();

                string sconn = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinanceDbContext"].ConnectionString;
                using (SqlConnection conn = new SqlConnection(sconn))
                {



                    //                    SqlDataAdapter adp = new SqlDataAdapter("select BPIV.Bill_Prep_Indvid, BPIV.Bill_Prepid, BPIV.Student_Classid, BPIV.RegistrationNo,"+
                    //"Cn.CL_Name, Cn.Class_Nameid, Se.Sessionid, Se.Session_Name, Tm.Termid, Tm.Term_Name, Bt.Bill_Typeid, Bt.Bill_Name, BPIV.Description, BPIV.Bill_Percent,"+
                    //"BPIV.Bill_Amount  from Bill_Prep_Indv BPIV"+
                    //"inner join Session Se ON  BPIV.Sessionid = Se.Sessionid"+
                    //"inner join Term Tm ON BPIV.Termid = Tm.Termid"+
                    //"inner join Class_Name Cn ON BPIV.Class_Nameid = Cn.Class_Nameid"+
                    //"inner join Bill_Type Bt ON BPIV.Bill_Typeid = Bt.Bill_Typeid"+
                    //"where BPIV.Sessionid = @Sessionid and BPIV.Termid = @Termid and BPIV.Bill_Typeid = @BTypeid", conn);

                    //SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    SqlDataAdapter adp = new SqlDataAdapter();
                    adp.SelectCommand = new SqlCommand();
                    adp.SelectCommand.Connection = conn;
                    adp.SelectCommand.CommandText = "Bill_Prep_IndvRepChild"; 
                    adp.SelectCommand.CommandType = CommandType.StoredProcedure;

                    // Sets the productid parameter.
                    adp.SelectCommand.Parameters.Add((new SqlParameter("@Sessionid", SqlDbType.Int)).Value = Sessionid);
                    //adp.SelectCommand.Parameters.Add((new SqlParameter("@Termid", SqlDbType.Int)).Value = Termid);
                    //adp.SelectCommand.Parameters.Add((new SqlParameter("@BTyped", SqlDbType.Int)).Value = BillTypeid);
                    //adp.SelectCommand = cmd;
                   // ds1.Tables.Add("Bill");
                    adp.Fill(ds2);
                   // adp.Fill(ds1);

                    // Sets the productid parameter.
                    //cmd.Parameters.Add((new SqlParameter("@Sessionid", SqlDbType.Int)).Value =  Sessionid);
                    //cmd.Parameters.Add((new SqlParameter("@Termid", SqlDbType.Int)).Value =  Termid);
                    //cmd.Parameters.Add((new SqlParameter("@BTyped", SqlDbType.Int)).Value = BTypeid);
                    // SqlCommand cmd = new SqlCommand();
                    //adp.SelectCommand = cmd;



                    adp.SelectCommand.CommandTimeout = 0;
                    // adp.Fill(dt,"Bill");
                    //adp.Fill(dt);


                    //SqlCommand comm1 = new SqlCommand("Select * from Session", conn);
                    //ds1.Tables.Add("Se");
                    //adp.SelectCommand = comm1;
                    //adp.Fill(ds1.Tables["Se"]);

                    //SqlCommand comm2 = new SqlCommand("Select * from Term", conn);
                    //ds1.Tables.Add("Tm");
                    //adp.SelectCommand = comm2;
                    //adp.Fill(ds1.Tables["Tm"]);

                    //SqlCommand comm3 = new SqlCommand("Select * from Bill_Type", conn);
                    //ds1.Tables.Add("Bt");
                    //adp.SelectCommand = comm3;
                    //adp.Fill(ds1.Tables["Bt"]);


                   // dt..Tables.Add("Bt");
                }
                 return ds2.Tables[0];
               // return ds2.Bill_Prep_Indv;

            }
            catch
            {
                throw;
            }
        }


 protected void reportViewer_Drillthrough(object sender, Microsoft.Reporting.WebForms.DrillthroughEventArgs e)
        {
            try
            {
                //BindingSource source = new BindingSource();
                //Microsoft.Reporting.WebForms.ReportDataSource dataSrc = new Microsoft.Reporting.WebForms.ReportDataSource();
                //dataSrc.Name = "DataSet1";
                //dataSrc.Value = this.DataTableBindingSource;

                //System.Data.DataSet ds = new System.Data.DataSet("Dataset2");
                //DataTable   dtBill = new DataTable("Bill");
                //string sconn = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolFinanceDbContext"].ConnectionString;
                //var conn = new SqlConnection(sconn);

                //SqlDataAdapter adp = new SqlDataAdapter();
                //adp.SelectCommand = new SqlCommand();
                //adp.SelectCommand.Connection = conn;
                //adp.SelectCommand.CommandText = "Bill_Prep_IndvRepChildUF";
                //adp.SelectCommand.CommandType = CommandType.StoredProcedure;
                int Sessionid = 0;
                //int Termid = 0;
                //int BillTypeid = 0;

                //adp.Fill(ds,"dtBill");

                //TimeSpan ts = new TimeSpan(0, 0, 10);

                // Cache["DsBill"] = ds1;
                //  Cache["DsBill"] = dtBill;
                // Cache.insert("Employee", dtBill, null, Cache.NoAbsoluteExpiration, ts);
                //  ds = (DataTable)Cache["ds1"];

                // ReportViewer reportViewer = new ReportViewer();
                //Get the instance of the Target report.
                LocalReport report = (LocalReport)e.Report;
               // report.DataSources.Add(dataSrc);

                //Get all the parameters passed from the main report to the target report.
                //OriginalParametersToDrillthrough actually returns a Generic list of
                //type ReportParameter.
                IList<ReportParameter> list = report.OriginalParametersToDrillthrough;

                //Parse through each parameters to fetch the values passed along with them.
                foreach (ReportParameter param in list)
                {
                    //Since we know the report has only one parameter and it is not a multivalued,
                    //we can directly fetch the first value from the Values array.
                    Sessionid = Convert.ToInt32(param.Values[0].ToString());
                    //Termid = Convert.ToInt32(param.Values[1].ToString());
                    //BillTypeid = Convert.ToInt32(param.Values[2].ToString());
                }

                //DataTable dt2 = GetBillReport(Sessionid);
                report.DataSources.Add(new ReportDataSource("DataSet1", GetBillReport(Sessionid)));
                // report.DataSources.Add(new ReportDataSource("DataSet1", ds1.Tables[0]));
                //report.DataSources.Add(new ReportDataSource("Session", ds1.Tables[1]));
                //report.DataSources.Add(new ReportDataSource("Term", ds1.Tables[2]));
                //report.DataSources.Add(new ReportDataSource("BillType", ds1.Tables[3]));
                //report.DataSources.Add(new ReportDataSource("Session", GetBillReport(Sessionid, Termid, BTypeid)));
                //report.DataSources.Add(new ReportDataSource("Term", GetBillReport(Sessionid, Termid, BTypeid)));
                //report.DataSources.Add(new ReportDataSource("BillType", GetBillReport(Sessionid, Termid, BTypeid)));
                // reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Report\Report4.rdlc";
                report.Refresh();

               // ViewBag.ReportViewer = report;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }

标签: eventsasp.net-mvc-5reportrdlcdrillthrough

解决方案


推荐阅读