Datasource for RDL reports with ReportViewer

若如初见. 提交于 2019-12-06 15:28:43
Paul Patterson

Did you verify the DataSourceReference element in your RDL? It needs the path to the reporting server.

The DataSourceReference element can contain a full folder path (for example, /SampleReports/AdventureWorks) or a relative path (for example, AdventureWorks). Relative paths start in the same folder as the report. The shared data source must be on the same server as the report.

Verify the DataSourceID too. Take a look at the answer on this question. It looks like it might be the same problem you are having.

If you are using an RDLC you could also set the datasource of your report manually using ReportDataSource. "GetMyData" in the example below would implement IEnumerable or 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);   

If you are converting an RDL to an RDLC you can follow the steps here. Note that you need to re-create data source and query information. Also, the XML schema definition is different between 2005 and 2008.

I suppose you are using the Report Viewer in local mode:

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local

and you use viewer.LocalReport. In this case you has to run query yourself and pass the result to the viewer:

dim tbl as new DataTable()

Fill the data e.g. tbl.load(datareader).

Dim VDS As New ReportDataSource
VDS.Name = "Your Data Source Name"
VDS.Value = tbl
viewer.LocalReport.DataSources.Add(VDS)

If you want to use server mode

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote

You has to use viewer.ServerReport

viewer.ServerReport.ReportServerUrl = New Uri(ReportServerURL)

and probably viewer.ServerReport.SetDataSourceCredentials

Reporting Services and ReportViewer Controls in Visual Studio

Edit
How to get queries from rdl
Initialization:

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)

Dataset Processing:

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

Note To convert vb.net<->c# I use Convert VB.NET to C#

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!