动态地将DataSource添加到ReportViewer [英] Adding DataSource to a ReportViewer dynamically

查看:103
本文介绍了动态地将DataSource添加到ReportViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ReportViewer,其中我动态加载了一个RDLC文件(本地处理模式)。我需要向ReportViewer提供数据,所以我尝试将新的ReportDataSource对象添加到ReportViewer.LocalReport.DataSources。

我得到的是一个ArgumentException,消息"值不属于预期范围"

sqlConnection1.ConnectionString = ConnectionString(connectionRef);
sqlCommand1.CommandType = CommandType.StoredProcedure;
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText = storedProcedureName;
sqlDataAdapter1.SelectCommand = sqlCommand1;

sqlDataAdapter1.TableMappings.Clear();
for(int i = 0; i< dsData.Tables.Count; i ++)
{sqlDataAdapter1.TableMappings.Add("Table"+(i == 0?"":i.ToString()),dsData.Tables [i] .TableName);
}
sqlDataAdapter1.Fill(dsData);


reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = @"C:\Temp \ReportEngine \ ReportEngine\ReportDefinition.rdlc";
reportViewer1.LocalReport.DataSources.Clear( );
ReadOnlyCollection< string> dataSourcesNames =(ReadOnlyCollection< string>)reportViewer1.LocalReport.GetDataSourceNames();

ReportDataSource rds = new ReportDataSource();
rds.Name = dataSourcesNames [0];
rds.Value = dsData; //< ------ - - - - - - - - - - - - -HERE罢工异常
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.RefreshReport( );

在我将类型化DataSet分配给ReportDataSource的Value属性的行中抛出异常。
我在这里做错了什么?

TIA! :)

I have a ReportViewer in which I dynamically loaded a RDLC file (Local Processing mode). I need to provide the data to the ReportViewer so I try to add a new ReportDataSource object to the ReportViewer.LocalReport.DataSources.

All I get is an ArgumentException with the message "Value does not fall within the expected range"

sqlConnection1.ConnectionString = ConnectionString(connectionRef);
sqlCommand1.CommandType = CommandType.StoredProcedure;
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText = storedProcedureName;
sqlDataAdapter1.SelectCommand = sqlCommand1;

sqlDataAdapter1.TableMappings.Clear();
for (int i = 0; i < dsData.Tables.Count; i++)
{
sqlDataAdapter1.TableMappings.Add("Table" + (i == 0 ? "" : i.ToString()), dsData.Tables[ i ].TableName);
}
sqlDataAdapter1.Fill(dsData);


reportViewer1.ProcessingMode = ProcessingMode.Local;
reportViewer1.LocalReport.ReportPath = @"C:\Temp\ReportEngine\ReportEngine\ReportDefinition.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
ReadOnlyCollection<string> dataSourcesNames = (ReadOnlyCollection<string>)reportViewer1.LocalReport.GetDataSourceNames();


ReportDataSource rds = new ReportDataSource();
rds.Name = dataSourcesNames[0];
rds.Value = dsData; // <------ - - - - - - - - - - - - -HERE STRIKES THE EXCEPTION
reportViewer1.LocalReport.DataSources.Add(rds);
reportViewer1.RefreshReport();


The exception is thrown at the line where I assign the typed DataSet to the ReportDataSource's Value property.
What am I doing wrong here?

TIA! :)

推荐答案

似乎我必须指定一个DataTable作为ReportDataSource的"Value"属性,而不是一个不允许的DataSet。

但是当我尝试将DataSource作为DataTable(类型化DataTable或无类型)添加到报表定义时,我得到:"必须安装服务'Microsoft.VisualStudio.Shell.Interop.IVsRunningDocumentTable'才能使此操作成功确保这项服务可用"

这让我很困惑,因为我安装了MS VS2005相当完整
It seems that I have to specify a DataTable as the "Value" property of the ReportDataSource not a DataSet which is not allowed.

However when I am trying to add a DataSource to the Report Definition as a DataTable (typed DataTable or untyped) I get : "The service 'Microsoft.VisualStudio.Shell.Interop.IVsRunningDocumentTable' must be installed for this operation to succeed. Ensure that this service is available"

This puzzles me as I've installed MS VS2005 quite complete


这篇关于动态地将DataSource添加到ReportViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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