我有一个reportviewer。我想动态生成一个数据表并将其设置为我的reportviewer的数据源。 reportviewer未显示数据。我的代码如下:
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = "report1.rdlc";
ReportDataSource rdS = new ReportDataSource("report", dt);
ReportViewer1.LocalReport.DataSources.Add(rdS);
有什么建议吗?
答案 0 :(得分:2)
试试这个:
ReportViewer1.Visible = true;
ReportViewer1.LocalReport.ReportPath = "report1.rdlc";
var datasource = new ReportDataSource("report", dt);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.Refresh();
答案 1 :(得分:1)
使用此代码
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportEmbeddedResource = @"D:\Projects\NIKHIL\NIKHIL\Report3.rdlc; viewer.LocalReport.ReportPath = @"D:\Projects\NIKHIL\NIKHIL\Report3.rdlc; viewer.LocalReport.DataSources.Clear();
viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables[0])); viewer.LocalReport.Refresh();
byteViewer = viewer.LocalReport.Render(reportType, deviceInfo, out mimeType, out encoding, out extension, out streamIds, out warnings);
答案 2 :(得分:-1)
如果ReportViewer没有显示数据(只是空白页面): 确保:确保DataTable中的列名与您在DataSource(数据库)中定义的列名相匹配。 (例如:如果数据库有一个名为'name_first'的columnName,那么您的DataTable也需要将columnName作为'name_first'。)