2011-12-14 171 views
3

我已經創建了rdlc報告。我的表單上有一個reportViewer。 當我嘗試加載我得到的報告時:「報告'xxxx.rdlc'的報告定義尚未指定」。我無法弄清楚這一點。 我有我需要的報告數據的數據表。 我拿這個數據表,我把它加載回我的數據庫,到一個名爲「FinalReport」的表。 (我這樣做的原因是因爲rdlc需要某種數據源。) 我的報告(table1)中有一張表。 這是我的代碼(我的表格,上報觀看者位於內):我在RDLC報告中收到「報告定義報告xxxx.rdlc未指定」

this.finalDataReportTableAdapter.Fill(this.nehasitDataSet.FinalDataReport); 
localReport.ReportEmbeddedResource = @"Resources\VisibleAssets.rdlc"; 
//I'm not so sure about the following line, but it's the only line that prevented me from getting an error ("no reportdefinition defined" 
using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc")) 
{ 
    localReport.LoadReportDefinition(rdlcSR); 

    localReport.Refresh(); 
} 

this.reportViewer.RefreshReport(); 

我也連接到DataTable的報告和的ReportViewer報告。 我真的不能看到問題,我搜索了Google。

任何幫助將不勝感激。

+1

您是否嘗試過將`reportViewer.LocalReport.ReportPath`屬性設置爲報表路徑? – jadarnel27 2011-12-14 15:12:41

回答

0

你在哪裏將localReport與你的reportViewer相關聯?相反的:

using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc")) 
    { 
     localReport.LoadReportDefinition(rdlcSR); 

     localReport.Refresh(); 
    } 

我用:

using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc")) 
    { 
     reportViewer1.LocalReport.LoadReportDefinition(rdlcSR); 

     reportViewer1.LocalReport.Refresh(); 
    } 

而且它似乎是爲我工作。

1

我得到了同樣的錯誤,但我以不同的方式加載我的報告。我遵循MSDN的說明。除了他們參考ReportEmbeddedResource我,而是,使用ReportPath。當我改變我的報告加載。

public partial class ReportViewer : Page 
{ 
    private bool _isReportViewerLoaded; 

    public ReportViewer() 
    { 
     InitializeComponent(); 
     _reportViewer.Load += _reportViewer_Load; 
    } 

    void _reportViewer_Load(object sender, EventArgs e) 
    { 
     if (!_isReportViewerLoaded) 
     { 
      Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource(); 
      BossbergDataset dataset = DataAccessConstants.myDataset; 

      dataset.BeginInit(); 

      reportDataSource1.Name = "DataSet1"; //Name of the report dataset in our .RDLC file 
      reportDataSource1.Value = dataset.Table1; 
      this._reportViewer.LocalReport.DataSources.Add(reportDataSource1); 
     //My testReport.Rdlc has the [Copy to Output Directory] set to [Copy Always] 
      this._reportViewer.LocalReport.ReportPath = @"Reports/TestReport.rdlc"; 

      dataset.EndInit(); 

      DataAccessConstants.Table1Adapter.Fill(dataset.Table1); 

      _reportViewer.RefreshReport(); 

      _isReportViewerLoaded = true; 
     } 
    } 
} 

隨着我的XAML是

<Page x:Class="MyProject.Views.ReportViewer" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xm![enter image description here][2]lns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" 
     mc:Ignorable="d" 
     d:DesignHeight="300" d:DesignWidth="300" 
    Title="ReportViewer"> 

    <Grid> 
     <WindowsFormsHost> 
      <rv:ReportViewer x:Name="_reportViewer"/> 
     </WindowsFormsHost> 
    </Grid> 
</Page> 

另外:

  • 確保您複製您的報告文件到你的輸出目錄。如果您使用的語法如../../Myreport.rdlc,那麼您可能不會複製到輸出目錄。 Output Directory requirements

  • 請確保您引用的是ReportViewer dll的正確版本。當我去參考>添加引用...> Assemblies> Extensions,並發現報告查看器的DLL它是一箇舊版本。我需要明確定位到

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\ReportViewer\Microsoft.ReportViewer.WinForms.dll

    要找到最新的。如果你弄錯了,你會得到一個錯誤,如

    報告定義無效。詳細信息:報告定義的無效目標命名空間'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition'無法升級。

1

有導致此問題,有時問題只可能發生在發佈同一應用程序IIS時的一些原因。如果報告文件(*。RDLC)在相關位置存在,問題仍然存在,你可以嘗試,以解決它下面的方法:

LocalReport.ReportEmbeddedResource Property on MSDN
「......嵌入報告資源是具有報表定義作爲資源存儲在調用程序集中。如果ReportPath屬性已設置,則ReportEmbeddedResource屬性將被忽略。這也導致裝載LoadReportDefinition報告被忽略「

更改:

reportViewer.LocalReport.ReportPath = Server.MapPath("~/Reporting/YourReportName.rdlc"); 

到:

rw.LocalReport.ReportEmbeddedResource = "YourFullNamespace.Reporting.YourReportName.rdlc"; 

然後Build Action屬性Embedded Resource從改變YourReportName.rdlc文件的屬性。希望這有助於...


0

正是你所說的那樣,因爲RDLC需要某種數據源的:)這是在報表查看器棘手的問題,解決它,我寫道,將結合的方法該報告從數據表直接:

private void GenerateReportDirect(ReportViewer reportViewer, string datasource, DataTable dt, string reportpath) 
{ 
    reportViewer.LocalReport.ReportPath = reportpath; 
    ReportDataSource repds = new ReportDataSource(datasource, dt); 
    reportViewer.LocalReport.DataSources.Clear(); 
    reportViewer.LocalReport.DataSources.Add(repds); 
    reportViewer.LocalReport.Refresh(); 
} 

和實現這個方法,你必須指定將數據集表適配器的字符串只是一個名字,但我們的報告將數據從數據表綁定(我們會欺騙我們的報告瀏覽器:))

private void BindReport(DataTable dt) 
    { 
      string reportPath = Server.MapPath("StudentBus.rdlc"); 
      GenerateReportDirect(ReportViewer1, "StudentDataSet_usp_RPT_StudentBus", dt, reportPath); 
    } 

我希望這會有所幫助:)。

0

我有一個同樣的問題發生在我的一個報告中。這是一份當地的嵌入式報告。

  1. 我沒有ReportEmbeddedResource屬性集。
  2. 當我沒設置ReportEmbeddedResource property,它仍然給了錯誤,因爲該報告的名稱有不正確的情況下 - myApp.reports.rptMyJobstatus.rdlc代替myApp.reports.rptMyJobStatus.rdlc

因此,您需要檢查這兩個條件。