简体   繁体   English

SSRS,单击按钮后在ReportViewer中更改报表

[英]SSRS, changing report in ReportViewer after clicking the button

I have finished the short course from Microsoft about creating Web App with reports from SQL Server Reporting Services (SSRS) (create-drillthrough-rdlc-report-with-parameters-reportviewer) 我已经完成了有关使用SQL Server Reporting Services(SSRS)的报告创建Web应用程序的Microsoft短期课程(create-drillthrough-rdlc-report-with-parameters-reportviewer)

During the course, i have created report, that allows drillthrough operation and links another Report (with another Dataset). 在课程中,我创建了报表,该报表允许追溯操作并链接另一个报表(与另一个数据集)。 That work's fine but for my purposes I need more control about the process, that's why I have created buttons to perform the same operation. 这项工作很好,但出于我的目的,我需要对该过程进行更多控制,所以才创建了执行相同操作的按钮。 Buttons are for retrieving new values from DB and showing results in current ReportViewer First button is performing data retrieving for the same report ( Report1 ) and dataset ( DataSet1 ) like parent report. 按钮用于从数据库中检索新值并在当前ReportViewer显示结果。第一个按钮正在对与父报告​​相同的报告( Report1 )和数据集( DataSet1 )执行数据检索。 Second one is retrieving data for another report ( Report2 ) and dataset ( DataSet2 ). 第二个是检索另一个报表( Report2 )和数据集( DataSet2 )的数据。

Code is almost the same, which was executed during standard drillthrough operation from tutorial, but hitting second button ( toReport2 ) does not showing any reuslts. 代码几乎与教程中的标准钻取操作期间执行的代码相同,但是单击第二个按钮( toReport2 )不会显示任何重用。 I don't know what is wrong here. 我不知道这是怎么回事。 I have checked the datatables results - the are existing and match the datasets. 我已经检查了数据表结果-存在并匹配数据集。 Going through of similar posts in WEB was not really helpfull. 在WEB中浏览类似的帖子并没有真正的帮助。 Please help me to resolve this. 请帮助我解决此问题。

protected void DataSet1Button_Click(object sender, EventArgs e)
{
    this.ReportViewer1.Reset();
    this.ReportViewer1.ProcessingMode = ProcessingMode.Local;
    this.ReportViewer1.LocalReport.DataSources.Clear();

    DataTable dt1 = getDataSet1Data();
    ReportDataSource datasource = new ReportDataSource("DataSet1", dt1);
    this.ReportViewer1.LocalReport.DataSources.Add(datasource);
    this.ReportViewer1.LocalReport.ReportPath = (@"...mypath...\MyApp7\Report1.rdlc");

    this.ReportViewer1.LocalReport.Refresh();
    this.ReportViewer1.Visible = true;

}

protected void DataSet2Button_Click(object sender, EventArgs e)
{
    this.ReportViewer1.Reset();
    this.ReportViewer1.ProcessingMode = ProcessingMode.Local;
    this.ReportViewer1.LocalReport.DataSources.Clear();

    DataTable dt2 = getDataSet2Data();
    ReportDataSource datasource2 = new ReportDataSource("DataSet2", dt2);
    this.ReportViewer1.LocalReport.DataSources.Add(datasource2);
    this.ReportViewer1.LocalReport.ReportPath = (@"...mypath...\MyApp7\Report2.rdlc");

    this.ReportViewer1.LocalReport.Refresh();
    this.ReportViewer1.Visible = true;

}

public DataTable getDataSet1Data()
{
    string constring = "Data Source = x.x.x.x; Initial Catalog = Adventureworks2014; Integrated Security = SSPI";
    using (SqlConnection sqlconn = new SqlConnection(constring))
    {
        string commandText = "SELECT ProductID, Name, ProductNumber, MakeFlag, FinishedGoodsFlag, Color, SafetyStockLevel, ReorderPoint, StandardCost, ListPrice, Size, SizeUnitMeasureCode, WeightUnitMeasureCode, Weight, DaysToManufacture, ProductLine, Class, Style, ProductSubcategoryID, ProductModelID, SellStartDate, SellEndDate, DiscontinuedDate, rowguid, ModifiedDate FROM Production.Product";
        using (SqlCommand sqlcomm = new SqlCommand(commandText, sqlconn))
        {
            using (SqlDataAdapter sqladap = new SqlDataAdapter(sqlcomm))
            {
                using (DataSet1 dset1 = new DataSet1())
                {
                    sqladap.Fill(dset1, dset1.Product.TableName);
                    return dset1.Product;
                }
            }
        }
    }
}
public DataTable getDataSet2Data()
{
    string constring = "Data Source = x.x.x.x; Initial Catalog = Adventureworks2014; Integrated Security = SSPI";
    using (SqlConnection sqlconn = new SqlConnection(constring))
    {
        string commandText = "SELECT PurchaseOrderID, PurchaseOrderDetailID, OrderQty, ProductID, ReceivedQty, RejectedQty, StockedQty FROM Purchasing.PurchaseOrderDetail";
        using (SqlCommand sqlcomm = new SqlCommand(commandText, sqlconn))
        {
            using (SqlDataAdapter sqladap = new SqlDataAdapter(sqlcomm))
            {
                using (DataSet2 dset2 = new DataSet2())
                {
                    sqladap.Fill(dset2, dset2.PurchaseOrderDetail.TableName);
                    return dset2.PurchaseOrderDetail;
                }
            }
        }
    }

Results from DataSet1Button_Click 来自DataSet1Button_Click的结果 来自DataSet1Button_Click的结果

Results from DataSet2Button_Click 来自DataSet2Button_Click的结果 来自DataSet2Button_Click的结果

Alright, solved! 好了,解决了! Comment from https://stackoverflow.com/users/2400834/tezzo was helpfull. 来自https://stackoverflow.com/users/2400834/tezzo的评论很有​​帮助。 Code is fine. 代码很好。 The problem was in Report2 settings, according which, addtional drillthrough parameter was expected. 问题出在Report2设置中,根据该设置,预期会出现其他钻取参数。 I have delete it and its working now. 我已经删除了它,现在可以正常工作了。 Problem seems to be silly but i my opinion, Microsoft should implement some notification for such cases. 问题似乎很愚蠢,但我认为,Microsoft应该为此类情况实施一些通知。

bugfix 错误修正

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM