数据表作为数据源中的ReportViewer数据源、数据表、ReportViewer

由网友(拾荒者.)分享简介:我想在ReportViewer控件的表组件被填入从数据表中的数据。换句话说,我想使用数据表作为源ReportViewer控件。我试图创建数据集,添加数据表与我的数据表将后的程序化填写详细的栏目,然后我用下面的code:I want the table component in reportviewer control...

我想在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);
阅读全文

相关推荐

最新文章