2016-03-15 24 views
1

我是新創建報表。在完成MSDN後,我創建了一個表並將其附加到reportViewer,但它沒有顯示任何內容。我有沒有做錯任何事情?使用datatable for reportviewer c#

DataSet ds = new DataSet("myDataset"); 

// create datatable 
DataTable dt = new DataTable("myDatatable"); 

       // add columns 
dt.Columns.Add("column1", typeof(string)); 
dt.Columns.Add("column2", typeof(string)); 
dt.Columns.Add("column3", typeof(string)); 

// insert data rows 
dt.Rows.Add("row1-col1", "row1-col2", "row1-col3"); 
dt.Rows.Add("row2-col1", "row2-col2", "row2-col3"); 



ds.Tables.Add(dt); 





BindingSource bs = new BindingSource(); 
bs.DataSource = ds; 


ReportDataSource rds = new ReportDataSource(); 
rds.Name = "dsBody"; 
rds.Value = ds.Tables["myDatatable"] ; 


reportViewer1.Reset(); 
reportViewer1.LocalReport.ReportPath = "C:\Temp\Report1.rdlc"; 
reportViewer1.LocalReport.DataSources.Clear(); 
reportViewer1.LocalReport.DataSources.Add(rds); 
reportViewer1.RefreshReport(); 
+0

向我們展示\ Report1.rdlc文件的一個片段?特別是dsBody部分,你所有的DataSet&DataTable代碼看起來都很好。 –

+0

Report1.rdlc是空白的,我應該在運行時通過數據表附加數據,我錯過了什麼? – phpnet

回答

0

這QA有解決方案,就像我說的,你需要的Tablix中,可以動態綁定您的DataTable的RDLC文件。

https://stackoverflow.com/a/22196065

開闢商業智能工作室(它包含在SQL Server報表服務),並插入一個Tablix控件到報告,然後再稍微的Tablix /網格的數據源屬性,以配合您的DataTable的名稱,保存並在rdlc文件中檢查XML。

一旦你得到所有的排序它應該開始工作(你可能會遇到一些奇怪的錯誤信息,但堅持),從基本開始獲取基本數據填充在您的報告。然後用你的生產報告完成它。