2010-11-23 47 views
2

我是新來的ssrs子報表部分。我已經設置了一些與標準表格,矩陣和tablix控件配合得很好的代碼,但一直無法加載子報表。我一直得到相同的SSRS子報表VS2010數據檢索失敗的子報表

有沒有人有任何使用Visual Studio 2010的子報表示例代碼?

錯誤消息「數據檢索失敗的子報表」。

我的代碼看起來像這樣,雖然我嘗試了一堆不同的場景來嘗試將數據傳遞到子報表。

private void LoadReport(string reportName) 
    { 
     reportViewer1.Clear(); 
     //http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/b039e765-3cc8-43ec-ae67-14b9656bc981 
     reportViewer1.Reset(); 
     // Set Processing Mode 
     reportViewer1.ProcessingMode = ProcessingMode.Local; 

     // Set RDL file 
     reportViewer1.LocalReport.ReportPath = reportName+".rdlc"; 

    } 

    public void LoadReport(IEnumerable products, string reportName, string dataSourceName) 
    { 
     LoadReport(reportName); 

     ReportParameter myParam = new ReportParameter("ReportParameter1", st.ToString() + " TO " + et.ToString()); 
      reportViewer1.LocalReport.SetParameters(new ReportParameter[] { myParam }); 

     reportViewer1.LocalReport.DataSources.Add(
      new ReportDataSource(dataSourceName, products)); 


     reportViewer1.LocalReport.DataSources.Add(
      new ReportDataSource(dataSourceName+"Subreport", products)); 

     // Process and render the report 
     reportViewer1.RefreshReport(); 
    } 

回答

3

從陳進微軟,ModeratorUsers獎牌 在MSDN論壇 http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/5d2aed0b-ea69-4cbb-b3c4-b306a48fbc30

THANK YOU SO MUCH答案!

我也有這樣的代碼,但是我已經在我通過GUI事件屬性窗口的事情

並按照你的榜樣,我搬到這條線

reportViewer1.LocalReport.SubreportProcessing添加的形式加入設計師活動+ = new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);

從form.designer.cs到刷新報告之後,就像您在示例中所做的一樣,現在它工作了!

謝謝你真棒感恩,呼

reportViewer1.RefreshReport(); reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);

private void reportViewer1_suberport1(object sender, SubreportProcessingEventArgs e) 
    { 

     ReportDataSource r=reportViewer1.LocalReport.DataSources[0]; 
     e.DataSources.Add(r); 

    } 

1

我沒有找到那動人的事件處理程序,以不同的斑點幫助這個特殊的錯誤。對於這個錯誤,固定它是什麼,以及你必須確保你的子報表可以無錯地運行。那麼,將它與主要報告結合起來。在我的情況下,我的報告在IDE中使用了不同於我在代碼中提供的數據集。