我已完成Microsoft关于使用SQL Server Reporting Services(SSRS)创建Web App的简短课程(create-drillthrough-rdlc-report-with-parameters-reportviewer)
在课程中,我创建了报告,允许钻取操作并链接另一个报告(使用另一个数据集)。这项工作很好但是为了我的目的,我需要更多地控制这个过程,这就是我创建按钮来执行相同操作的原因。按钮用于从DB检索新值并在当前ReportViewer
中显示结果第一个按钮正在执行同一报告( Report1 )和数据集( DataSet1 )的数据检索像父母报告。第二个是检索另一个报告( Report2 )和数据集( DataSet2 )的数据。
代码几乎相同,在教程的标准钻取操作期间执行,但是点击第二个按钮( toReport2 )没有显示任何重新连接。我不知道这里有什么问题。 我检查了数据表结果 - 存在并匹配数据集。 浏览WEB中的类似帖子并不是很有帮助。请帮我解决这个问题。
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;
}
}
}
}
答案 0 :(得分:0)
好的,解决了! 来自https://stackoverflow.com/users/2400834/tezzo的评论很有帮助。代码很好。问题出在Report2设置中,根据该设置,预计会增加钻取参数。我删除了它,现在正在工作。 问题似乎很愚蠢,但我认为,微软应该针对此类情况实施一些通知。