1

SQL Server BI Development Studioで作成されたRDLレポートがいくつかありますが、ASP.NETレポートビューアーを使用してそれらをレンダリングする必要があります。RDLにはSQLサーバーとSELECTクエリへの参照が含まれていますが、レポートのデータソースを指定する必要があると言われ続けます。RDLからのデータソースを使用する方法はありますか、それともC#コードを介してデータソースをレポートビューアーに渡す必要がありますか?

ありがとうございました。

4

2 に答える 2

5

Report Viewer をローカル モードで使用しているとします。

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

を使用しますviewer.LocalReport。この場合、自分でクエリを実行し、結果をビューアに渡す必要があります。

dim tbl as new DataTable()

tbl.load(datareader) などのデータを入力します。

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.ReportServerUrl = New Uri(ReportServerURL)

そしておそらくviewer.ServerReport.SetDataSourceCredentials

Visual Studio の Reporting Services と ReportViewer コントロール


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.net<->c# を変換するには、 Convert VB.NET to C#を使用します

于 2012-04-17T13:53:27.293 に答える
1

RDL の DataSourceReference 要素を確認しましたか? レポート サーバーへのパスが必要です。

DataSourceReference 要素には、完全なフォルダー パス (/SampleReports/AdventureWorks など) または相対パス (AdventureWorks など) を含めることができます。相対パスは、レポートと同じフォルダーから始まります。共有データ ソースは、レポートと同じサーバー上にある必要があります。

DataSourceID も確認します。この質問の答えを見てください。あなたが抱えているのと同じ問題があるようです。

RDLC を使用している場合は、 ReportDataSource を使用してレポートのデータソースを手動で設定することもできます。以下の例の「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 に変換する場合は、こちらの手順に従ってください。データ ソースとクエリ情報を再作成する必要があることに注意してください。また、2005 年と 2008 年では XML スキーマの定義が異なります。

于 2012-04-09T13:30:32.707 に答える