2011-08-08 11 views
2

Visual Studio 2010で.Net 4.0とC#を使用して、ListからReportViewerレポートを生成する小さなアプリケーションを構築しています。私は、WebLinkからProviderIdentifierというプロパティ値を渡すべきサブテーブルをtablixに持っています。私はこのようなサブレポートにデータを返すために私のレポートにSubReportProcessing-イベントを実装:サブレポートでnullエラーが発生するReportViewer

private void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e) 
{ 
    List<WebLink> links = LinkProvider.FetchSublinks(LinkProvider.Fetch(new WebLink(new Uri("http://www.contentstudio.se/")))); 
    e.DataSources.Add(new ReportDataSource("ParentLinks", links)); 
} 

は現在、私は、サブレポートのすべてのインスタンスで同じリンクを返します。サブレポートにパラメータを渡そうとするまで、レポートは正常に機能します。 ProviderIdentifier(問題なくレポートに表示できる)を使用してパラメータを追加すると、「オブジェクトのインスタンスがオブジェクトのインスタンスに設定されていません」というメッセージで常にNullReferenceExceptionが発生します。私は私のLocalReportオブジェクトのRender()を呼び出すとき。 ProviderIdentifierを渡す代わりに静的な値(1など)をレポートに追加する場合も同じことが起こります。パラメータをまとめて削除すると効果的ですが、サブレポートに返すリンクを特定する方法がありません。

誰でもこの問題の原因を知ることができますか?

完全なコード:

public void RenderReport() 
{ 
    LocalReport localReport = new LocalReport 
            { 
             ReportPath = ("BrokenLink.rdlc"), 
             EnableHyperlinks = true, 
             ShowDetailedSubreportMessages = true 
            }; 

    List<WebLink> links = LinkProvider.FetchSublinks(LinkProvider.Fetch(new WebLink(new Uri("http://www.contentstudio.se/")))); 

    ReportDataSource reportDataSource = new ReportDataSource("Weblinks", links); 
    localReport.DataSources.Add(reportDataSource); 

    localReport.SubreportProcessing += localReport_SubreportProcessing; 

    const string reportType = "PDF"; 
    string mimeType; 
    string encoding; 
    string fileNameExtension; 

    //The DeviceInfo settings should be changed based on the reportType 
    //http://msdn2.microsoft.com/en-us/library/ms155397.aspx 
    const string deviceInfo = "<DeviceInfo>" + 
           " <OutputFormat>PDF</OutputFormat>" + 
           " <PageWidth>8.5in</PageWidth>" + 
           " <PageHeight>11in</PageHeight>" + 
           " <MarginTop>0.5in</MarginTop>" + 
           " <MarginLeft>1in</MarginLeft>" + 
           " <MarginRight>1in</MarginRight>" + 
           " <MarginBottom>0.5in</MarginBottom>" + 
           " <DpiX>72</DpiX>" + 
           " <DpiY>72</DpiY>" + 
           "</DeviceInfo>"; 
    Warning[] warnings; 
    string[] streams; 

    //Render the report 
    byte[] renderedBytes = localReport.Render(
     reportType, 
     deviceInfo, 
     out mimeType, 
     out encoding, 
     out fileNameExtension, 
     out streams, 
     out warnings); 

    File.WriteAllBytes("I:\\report.pdf", renderedBytes); 
} 

答えて

4

それは数時間かかりましたが、私は最終的に私が見逃していたものを見つけました。レポートのプロパティをチェックすると、メインレポートから来るパラメータの一致を作成するためのさまざまな方法をテストした「変数」を設定できます。私が完全に見逃していたのは(ネット上で正しく記述できなかった)エディタの右側のツリービューに "Parameters"というフォルダがあります。私は、私のメインレポートが通過しているものに対応するパラメータをそこに追加しました。

関連する問題