本文介绍了我怎样才能加载数据表作为ReportDataSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做这样的事情:

this.reportViewer.LocalReport.DataSources.Clear();
DataTable dt = new DataTable();
dt = this.inputValuesTableAdapter.GetData();
Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource();

rprtDTSource = dt; // this line generates exception

//this.reportViewer.LocalReport.DataSources.Add(rprtDTSource);
this.reportViewer.RefreshReport();

我如何可以加载数据表作为ReportDataSource?

How can I load datatable as ReportDataSource?

目前的code生产:
无法隐式转换类型'System.Data.DataTable'到'Microsoft.Reporting.WinForms.ReportDataSource'

The current code produces:"Cannot implicitly convert type 'System.Data.DataTable' to 'Microsoft.Reporting.WinForms.ReportDataSource' "

推荐答案

您没有正确初始化ReportDataSouce。试试这个:

You are not initializing the ReportDataSouce correctly. Give this a try:

this.reportViewer.LocalReport.DataSources.Clear();
DataTable dt = new DataTable();
dt = this.inputValuesTableAdapter.GetData();

Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(dt.TableName, dt);

this.reportViewer.LocalReport.DataSources.Add(rprtDTSource);
this.reportViewer.RefreshReport();

此外,您可能需要改变的第一个参数的构造函数ReportDataSource来设置你的报告预计数据源的名称。

Also, you might need to alter the first parameter to the ReportDataSource constructor to set the name of the datasource that your report is expecting.

这篇关于我怎样才能加载数据表作为ReportDataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 05:18