数据表作为 ReportViewer 中的数据源 [英] Datatable as datasource in ReportViewer

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

问题描述

我希望使用数据表中的数据填充报表查看器控件中的表格组件.换句话说,我想使用数据表作为报表查看器控件的源.我尝试创建数据集,添加了数据表,其中包含我的数据表在以编程方式填充后将具有的确切列.然后我使用了以下代码:

I want the table component in reportviewer control to be filled in with data from datatable. In other words, i want to use datatable as source for reportviewer control. I tried to create dataset, added datatable with exact columns that my datatable will have after programmatical fill in. Then I used the following code:

 DataTable dt = new DataTable();
 dt.TableName = "DataTable1";
 conn.Open();
 adapter.Fill(dt);
 ReportViewer1.ProcessingMode=ProcessingMode.Local;
 ReportDataSource source = new ReportDataSource("SampleDs", dt);
 ReportViewer1.LocalReport.DataSources.Clear();
 ReportViewer1.LocalReport.DataSources.Add(source);
 ReportViewer1.DataBind();
 ReportViewer1.LocalReport.Refresh();

然而,这行不通.我得到的唯一消息是:

However, that does not work. The only message I get is:

报告处理过程中发生错误.SampleDs.

An error has occurred during report processing. SampleDs.

谁能告诉我如何解决问题或指出创建此类报告的完整过程的参考,

Can anyone tell me how to solve issue or point out to the refference where full process of creating such report described,

推荐答案

您用于 ReportDataSource 对象需要第一个参数中的数据源名称.你没有提供这个,你需要数据表名称.

The overload you're using for the constructor of the ReportDataSource object is expecting the name of the data source in that first parameter. You're not supplying this, you need the DataTable name.

将您的代码更新为此,您应该没问题:

Update your code to this and you should be OK:

ReportDataSource source = new ReportDataSource("DataTable1", dt);

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

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