![](/img/trans.png)
[英]Running a LocalReport with a remote SSRS DataSource in ASP.NET ReportViewer control
[英]ReportViewer with multiple dataset running in localreport
我需要在本地處理模式下使用兩個數據源執行ReportViewer,但是第二個卻有問題。
我使用報表生成器3設計報表,並且在該報表上運行良好(兩個數據集都填充了各自的表)。
但是,當我使用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"));
我打開xml讀取SQL查詢並替換參數,在服務器中運行查詢並加載DataTable,我為每個查詢執行此操作,兩個命令都獲取數據。
然后,只需將兩個數據源添加到報告中並將其呈現為PDF。
問題是在代碼中,第二個表仍然為空:
良好: http : //i.imgur.com/6wWpVMA.png
錯誤: http : //i.imgur.com/JJz3K33.png
所以,問題是,為什么呢?
謝謝!
我終於找到了解決方案!
我只是在“數據源屬性”對話框中選中“處理查詢時的用戶單個事務”選項,它可以正常工作!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.