I want to do a bind datatable to reportviewer with the code below. I don't see the results appear in the reportviewer, what the lack of script below?
// create dataset
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");
// add datatable to dataset
ds.Tables.Add(dt);
// bind datatable to report viewer
this.reportViewer.Reset();
this.reportViewer.ProcessingMode = ProcessingMode.Local;
this.reportViewer.LocalReport.ReportEmbeddedResource = "Test.Report1.rdlc";
this.reportViewer.LocalReport.DataSources.Clear();
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource(dt.TableName, dt));
this.reportViewer.RefreshReport();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…