如何在ReportViewer中将Datatable设置为数据源 [英] how to set Datatable as datasource in ReportViewer

查看:256
本文介绍了如何在ReportViewer中将Datatable设置为数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Datable 中的数据源 ReportViewer 我发现这是解决方案

  DataTable table = new DataTable(); 
table.Columns.Add(value,typeof(string));
table.Columns.Add(price,typeof(string));
table.Columns.Add(quantity,typeof(string));

table.Rows.Add(test1,10,20);
table.Rows.Add(test2,10,20);

reportViewer1.LocalReport.DataSources.Clear();

ReportDataSource rprtDTSource = new ReportDataSource(TITLE,表);

reportViewer1.LocalReport.DataSources.Add(rprtDTSource);
reportViewer1.RefreshReport();

但我得到这个图像作为结果





有什么问题?

解决方案

您似乎忘记为报表查看器控件设置报表源。您可以使用以下任一选项设置报告来源:





  • I was searching in the last question about Datatable as datasource in ReportViewer and i found this as solution

    DataTable table = new DataTable();
    table.Columns.Add("value", typeof(string));
    table.Columns.Add("price", typeof(string));
    table.Columns.Add("quantity", typeof(string));
    
    table.Rows.Add("test1","10","20");
    table.Rows.Add("test2", "10", "20");
    
    reportViewer1.LocalReport.DataSources.Clear();
    
    ReportDataSource rprtDTSource = new ReportDataSource("TITLE",table);
    
    reportViewer1.LocalReport.DataSources.Add(rprtDTSource);
    reportViewer1.RefreshReport();
    

    but i get this image as result

    what is the problem ??

    解决方案

    It seems you have forgotten to set the report source for your report viewer control. You can set the report source using either of this options:

    For example, I suppose you have added a report to your project, so you can show it in the report viewer this way:

    var reportDataSource1 = new ReportDataSource("NameOfReportDataSet", YourDataTable);
    this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
    this.reportViewer1.LocalReport.ReportEmbeddedResource = "Namespace.ReportName.rdlc";
    this.reportViewer1.RefreshReport();
    

    Also you can simply set the report of the report viewer using designer. Put a report viewer on your form and click on top-right arrow to open the smart tag window of report viewer, then choose a report from combo box.

    这篇关于如何在ReportViewer中将Datatable设置为数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆