Asp.net 使用ReportViewer的RDL报告的数据源

Asp.net 使用ReportViewer的RDL报告的数据源,asp.net,reporting-services,reportviewer,rdl,Asp.net,Reporting Services,Reportviewer,Rdl,我有一些使用SQL Server BI Development Studio创建的RDL报告,现在我需要使用ASP.NET报告查看器呈现它们。尽管我的RDL包含对SQL server和SELECT查询的引用,但它一直说我需要为报表指定一个数据源。有没有办法使用RDL中的数据源,或者我必须通过C代码将数据源传递给报表查看器 谢谢。您是否验证了RDL中的DataSourceReference元素?它需要到报表服务器的路径 DataSourceReference元素可以包含 例如,/SampleRep

我有一些使用SQL Server BI Development Studio创建的RDL报告,现在我需要使用ASP.NET报告查看器呈现它们。尽管我的RDL包含对SQL server和SELECT查询的引用,但它一直说我需要为报表指定一个数据源。有没有办法使用RDL中的数据源,或者我必须通过C代码将数据源传递给报表查看器


谢谢。

您是否验证了RDL中的DataSourceReference元素?它需要到报表服务器的路径

DataSourceReference元素可以包含 例如,/SampleReports/AdventureWorks或的相对路径 例如,AdventureWorks。相对路径在与相同的文件夹中开始 报告。共享数据源必须与服务器位于同一服务器上 报告

还要验证数据源ID。请看下面的图片。看起来可能和你的问题一样

如果您使用的是RDLC,还可以使用手动设置报表的数据源。下面示例中的GetMyData将实现IEnumerable或IDataSource

ReportDataSource reportDataSource = new ReportDataSource("MyDataName", GetMyData(startAt, endAt));
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reporting/MyReport.rdlc");

ReportParameterCollection col = new ReportParameterCollection();
ReportParameter startAtParam = new ReportParameter("StartAt", startAt.ToString("MMM, dd yyyy"));
col.Add(startAtParam);
ReportParameter endAtParam = new ReportParameter("EndAt", endAt.ToString("MMM, dd yyyy"));
col.Add(endAtParam);

ReportViewer1.LocalReport.SetParameters(col);   

如果要将RDL转换为RDLC,则可以。请注意,您需要重新创建数据源和查询信息。此外,XML模式定义在2005年和2008年之间有所不同。

您是否验证了RDL中的DataSourceReference元素?它需要到报表服务器的路径

DataSourceReference元素可以包含 例如,/SampleReports/AdventureWorks或的相对路径 例如,AdventureWorks。相对路径在与相同的文件夹中开始 报告。共享数据源必须与服务器位于同一服务器上 报告

还要验证数据源ID。请看下面的图片。看起来可能和你的问题一样

如果您使用的是RDLC,还可以使用手动设置报表的数据源。下面示例中的GetMyData将实现IEnumerable或IDataSource

ReportDataSource reportDataSource = new ReportDataSource("MyDataName", GetMyData(startAt, endAt));
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reporting/MyReport.rdlc");

ReportParameterCollection col = new ReportParameterCollection();
ReportParameter startAtParam = new ReportParameter("StartAt", startAt.ToString("MMM, dd yyyy"));
col.Add(startAtParam);
ReportParameter endAtParam = new ReportParameter("EndAt", endAt.ToString("MMM, dd yyyy"));
col.Add(endAtParam);

ReportViewer1.LocalReport.SetParameters(col);   

如果要将RDL转换为RDLC,则可以。请注意,您需要重新创建数据源和查询信息。此外,XML模式定义在2005年和2008年之间有所不同。

我想您是在本地模式下使用报表查看器:

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
您可以使用viewer.LocalReport。在这种情况下,您必须自己运行查询并将结果传递给查看器:

dim tbl as new DataTable()
填写数据,例如tbl.loaddatareader

Dim VDS As New ReportDataSource
VDS.Name = "Your Data Source Name"
VDS.Value = tbl
viewer.LocalReport.DataSources.Add(VDS)
如果要使用服务器模式

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
您必须使用viewer.ServerReport

可能还有viewer.ServerReport.setDataSourceRedentials

编辑 如何从rdl获取查询 初始化:

Dim XRep As New XmlDocument
XRep.Load(ReportPath)
Dim xmlnsManager As New System.Xml.XmlNamespaceManager(XRep.NameTable)
dim DefaultNSURI as string = XRep.GetElementsByTagName("Width")(0).NamespaceURI
xmlnsManager.AddNamespace("rep", DefaultNSURI)
数据集处理:

For Each nd As XmlNode In XRep.SelectNodes("/rep:Report/rep:DataSets/rep:DataSet", xmlnsManager)
   'DataSourceName can be used to find iformation about connection' 
   Dim DataSourceName As String = nd.SelectSingleNode("rep:Query/rep:DataSourceName", xmlnsManager).InnerText  
   Dim DSName As String = nd.Attributes("Name").Value       
   cmd.CommandText = nd.SelectSingleNode("rep:Query/rep:CommandText", xmlnsManager).InnerText
   Dim tbl As New DataTable(DSName)
   tbl.Load(cmd.ExecuteReader)
    'The table created here is to be passed to  LocalReport as datasource'
 Next

要转换vb.netc,我使用

我假设您在本地模式下使用报表查看器:

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
您可以使用viewer.LocalReport。在这种情况下,您必须自己运行查询并将结果传递给查看器:

dim tbl as new DataTable()
填写数据,例如tbl.loaddatareader

Dim VDS As New ReportDataSource
VDS.Name = "Your Data Source Name"
VDS.Value = tbl
viewer.LocalReport.DataSources.Add(VDS)
如果要使用服务器模式

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
您必须使用viewer.ServerReport

可能还有viewer.ServerReport.setDataSourceRedentials

编辑 如何从rdl获取查询 初始化:

Dim XRep As New XmlDocument
XRep.Load(ReportPath)
Dim xmlnsManager As New System.Xml.XmlNamespaceManager(XRep.NameTable)
dim DefaultNSURI as string = XRep.GetElementsByTagName("Width")(0).NamespaceURI
xmlnsManager.AddNamespace("rep", DefaultNSURI)
数据集处理:

For Each nd As XmlNode In XRep.SelectNodes("/rep:Report/rep:DataSets/rep:DataSet", xmlnsManager)
   'DataSourceName can be used to find iformation about connection' 
   Dim DataSourceName As String = nd.SelectSingleNode("rep:Query/rep:DataSourceName", xmlnsManager).InnerText  
   Dim DSName As String = nd.Attributes("Name").Value       
   cmd.CommandText = nd.SelectSingleNode("rep:Query/rep:CommandText", xmlnsManager).InnerText
   Dim tbl As New DataTable(DSName)
   tbl.Load(cmd.ExecuteReader)
    'The table created here is to be passed to  LocalReport as datasource'
 Next

要转换vb.netc,我使用了

,我想我把这里的东西搞混了。我做了更多的研究,发现我真正需要的是一个RDLC,因为我想在不涉及报表服务器的情况下使用报表查看器呈现报表定义。尽管如此,我仍然需要使用RDLC文件中的数据集和数据源。我走的方向正确吗?但不可能只将RDL转换为RDLC,保留来自RDL的dataset和datasource规范并使用它们,而不必做所有声明吗?我的意思是,如果我已经在RDL上指定了一个查询和一个指向SQL Server的路径,我就不会再这样做了,因为我不再在服务器上呈现该报表了。希望我很清楚。你用什么版本的Visual Studio制作报告?看看“如何转换报告定义”的步骤,我想我在这里把事情搞混了。我做了更多的研究,发现我真正需要的是一个RDLC,因为我想在不涉及报表服务器的情况下使用报表查看器呈现报表定义。尽管如此,我仍然需要使用RDLC文件中的数据集和数据源。我走的方向正确吗?但不可能只将RDL转换为RDLC,保留来自RDL的dataset和datasource规范并使用它们,而不必做所有声明吗?我的意思是,如果我已经在RDL上指定了一个查询和一个指向SQL Server的路径,我就不会再这样做了,因为我不再在服务器上呈现该报表了。希望我很清楚。你用什么版本的Visual Studio制作报告?请看一下“如何转换报告定义”步骤