簡體   English   中英

將數據表用於reportviewer c#

[英]Using datatable for reportviewer c#

我是創建報告的新手。 遵循MSDN之后,我創建了一個表並將其附加到reportViewer,但是它不顯示任何內容。 我做錯了什么嗎?

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();

這個QA提供了解決方案,就像我說過的那樣,您需要rdlc文件中的Tablix,以便可以動態綁定DataTable。

https://stackoverflow.com/a/22196065

打開Business Intelligence Studio(它包含在Sql Server Reporting Services中)並將Tablix控件插入到報表中,然后調整Tablix / grid的數據源屬性以匹配DataTable的名稱,保存並檢查XML中的XML rdlc文件。

完成所有排序后,它應該開始工作(您可能會遇到一些奇怪的錯誤消息,但是仍然存在),請從basic開始,以便在報告中填充基本數據。 然后用您的生產報告完成它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM