[英]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.