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

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

问题描述

我想在ReportViewer控件的表组件被填入从数据表中的数据。换句话说,我想使用数据表作为源ReportViewer控件。我试图创建数据集,添加数据表与我的数据表将后的程序化填写详细的栏目,然后我用下面的code:

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.

谁能告诉我怎么解决问题,或者指出对REFFERENCE在那里创造描述了这样的报告全过程,

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.

更新您的code到这一点,你应该确定:

Update your code to this and you should be OK:

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

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

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