本文介绍了动态地将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! :)

推荐答案


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

08-22 23:28
查看更多