简体   繁体   English

在本地报表中运行多个数据集的ReportViewer

[英]ReportViewer with multiple dataset running in localreport

I need excecute a ReportViewer in local processing mode with two data sources, but I have a problem with the second. 我需要在本地处理模式下使用两个数据源执行ReportViewer,但是第二个却有问题。

I desing the report with report builder 3 and it run fine there (both dataset fill their respectives tables). 我使用报表生成器3设计报表,并且在该报表上运行良好(两个数据集都填充了各自的表)。

But when I render the report in C#, the second dataset is empty, this is the code: 但是,当我使用C#渲染报表时,第二个数据集为空,这是代码:

SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = nodoDataSet[0].FirstChild.InnerText.ToString().Replace("@Id", id.ToString());
System.Data.DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());

SqlCommand cmd2 = new SqlCommand();
cmd2.Connection = con;
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = nodoDataSet[1].FirstChild.InnerText.ToString().Replace("@Id", id.ToString());
System.Data.DataTable dt2 = new DataTable();
dt2.Load(cmd2.ExecuteReader());

con.Close();

ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = urlReporte;
viewer.LocalReport.DataSources.Add(new ReportDataSource() { Name = "Consulta", Value = dt });
viewer.LocalReport.DataSources.Add(new ReportDataSource() { Name = "Consulta2", Value = dt2 });
viewer.LocalReport.EnableExternalImages = true;

List<ReportParameter>() parametros = new List<ReportParameter>(){
    new ReportParameter("Id",id.ToString()),
};
viewer.LocalReport.SetParameters(parametros);
pdf.Add(viewer.LocalReport.Render("PDF"));

I open the xml to read the SQL query and replace the parameters, run the query in the server and load a DataTable, I do this for each query, both commands get data. 我打开xml读取SQL查询并替换参数,在服务器中运行查询并加载DataTable,我为每个查询执行此操作,两个命令都获取数据。

Then just add the two data sources to the report and render it as PDF. 然后,只需将两个数据源添加到报告中并将其呈现为PDF。

The problem is that in the code, the second table remains empty: 问题是在代码中,第二个表仍然为空:

Good: http://i.imgur.com/6wWpVMA.png 良好: http//i.imgur.com/6wWpVMA.png

Bad: http://i.imgur.com/JJz3K33.png 错误: http//i.imgur.com/JJz3K33.png

So, the question is, why? 所以,问题是,为什么呢?

Thanks! 谢谢!

I finally found the solution! 我终于找到了解决方案!

I just check the "User single transaction when processing the queries" option in the Data Source Properties dialog and it works! 我只是在“数据源属性”对话框中选中“处理查询时的用户单个事务”选项,它可以正常工作!

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

相关问题 在ASP.NET ReportViewer控件中使用远程SSRS数据源运行LocalReport - Running a LocalReport with a remote SSRS DataSource in ASP.NET ReportViewer control 在winform的ReportViewer的LocalReport中导出为CSV - Export to CSV in LocalReport of ReportViewer of winform reportviewer.LocalReport.GetTotalPages()返回0或错误 - reportviewer.LocalReport.GetTotalPages() returns 0 or error reportviewer.LocalReport.GetTotalPages()有时返回1或2 - reportviewer.LocalReport.GetTotalPages() returns sometimes 1 or 2 以黑白PDF格式从Reportviewer渲染LocalReport - Render LocalReport from Reportviewer in Black and White PDF Visual Studio中devexpress的ReportViewer控件无法识别LocalReport属性 - ReportViewer control of devexpress in visual studio that does not recognize the LocalReport property 从Microsoft.ReportViewer.LocalReport中导出PDF导出中的条形码 - Rendering barcodes in PDF export from Microsoft.ReportViewer.LocalReport ReportViewer.LocalReport.Refresh和ReportViewer.RefreshData有什么区别? - What's the difference between ReportViewer.LocalReport.Refresh and ReportViewer.RefreshData? 刷新ReportViewer中数据集中的字段 - Refresh fields in Dataset in ReportViewer 将数据集发送到reportviewer进行显示 - Sending a Dataset to reportviewer for display
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM