如何使用编码运行 rdlc

发布于 2024-09-07 18:53:00 字数 1210 浏览 3 评论 0原文

我创建了一个 rdlc,其中使用数据集作为解决方案资源管理器中的新项目来设计我的报告。从名为 Dataset1数据源绑定我的报告后。我已经创建了它的对象并尝试使用编码来填充此数据源。现在,当我运行以下代码时,我没有得到任何结果。

可能是什么问题?

reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
LocalReport localReport = reportViewer1.LocalReport;
localReport.DataSources.Clear();
localReport.ReportPath = @"E:\Projects\Manojp\AARFID_SSRS_Report\WindowsFormsApplication1\WindowsFormsApplication1\Local Report\rptTest.rdlc";

// DataSet dataset = new DataSet("AARFID_Report");
DataSet1 ds = new DataSet1();

// fill the Data Set from DataBase.
//ds.Tables.Remove("M_GUEST");
ds.Tables.Clear();
GetData(ref ds);

//
// Create a report data source for the sales order data

ReportDataSource rds = new ReportDataSource();
rds.Name = "AA";
rds.Value = ds.Tables[0];
localReport.DataSources.Add(rds); 
// reportViewer1.LocalReport.DataSources.Add(rds); 


reportViewer1.RefreshReport();
localReport.DataSources.Clear();

GetData() 执行此操作:

connection.Open();
ad.Fill(ds,"M_GUEST");
connection.Close();

在报告视图中,消息显示为:

尚未为数据源“dtaset1_m_guest”提供数据源实例

I have created an rdlc where I have used dataset taken as a new item in solution explorer for designing my report. After binding my report from that datasource which is named as Dataset1. I have created its object and tried to fill this datasource using coding. Now when I runs the following code I am not getting any result.

What can be the issue?

reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
LocalReport localReport = reportViewer1.LocalReport;
localReport.DataSources.Clear();
localReport.ReportPath = @"E:\Projects\Manojp\AARFID_SSRS_Report\WindowsFormsApplication1\WindowsFormsApplication1\Local Report\rptTest.rdlc";

// DataSet dataset = new DataSet("AARFID_Report");
DataSet1 ds = new DataSet1();

// fill the Data Set from DataBase.
//ds.Tables.Remove("M_GUEST");
ds.Tables.Clear();
GetData(ref ds);

//
// Create a report data source for the sales order data

ReportDataSource rds = new ReportDataSource();
rds.Name = "AA";
rds.Value = ds.Tables[0];
localReport.DataSources.Add(rds); 
// reportViewer1.LocalReport.DataSources.Add(rds); 


reportViewer1.RefreshReport();
localReport.DataSources.Clear();

GetData() do this:

connection.Open();
ad.Fill(ds,"M_GUEST");
connection.Close();

In the report view a message is shown as:

A data source instance has not been supplied for the data source 'dtaset1_m_guest'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

戈亓 2024-09-14 18:53:08

如果绑定中的数据源名为“Dataset1”,那么您在代码中的数据源也应命名相同。

我添加它就像这样完美地执行此操作,如下所示:

 reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Dataset1", ds.Tables[0]));

If the DataSource in binding is named "Dataset1" then the one you your in code should also name the same.

I add it like this works perfectly do this as below:

 reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Dataset1", ds.Tables[0]));
2024-09-14 18:53:07

当您通过向导在项目中添加 .rdlc 报告时,默认情况下它将数据集名称设为 'DataSet1' 。现在,如果您想动态绑定新数据集,则该数据集的名称必须是“DataSet1”。尝试更改它,并检查 Table[0] 是否包含一些数据(行),其数据类型与“DataSet1”的原始数据类型匹配。如果数据类型不匹配,则数据将不会出现在您的 ReportViewer 中。尝试此代码:-

string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Reports\SessionReport.rdlc");
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = reportPath;
this.reportViewer1.RefreshReport();

有关 .rdlc 报告(核心逻辑)的更多详细信息,请参阅以下链接
如何在没有数据库的情况下创建报告(RDLC)?

When you add .rdlc report in your project by wizard then by default it take dataset name as 'DataSet1' . Now if you want to bind dynamically new dataset then name of that dataset must be 'DataSet1'. Try change it and also check that Table[0] contains some data(Rows) for which DataType get matched with original dataType of 'DataSet1'. If DataType doesn't matches then data wont come in your ReportViewer. Try this code:-

string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Reports\SessionReport.rdlc");
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", ds.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = reportPath;
this.reportViewer1.RefreshReport();

For more detail about .rdlc report(Core logic) refer following link
How to create report (RDLC) without database?

幸福还没到 2024-09-14 18:53:06

该行

rds.Name = "AA"; 

必须与报告中定义的数据集名称匹配。在你的情况下,那就是

rds.Name = "dtaset1_m_guest"; 

This line

rds.Name = "AA"; 

must match the name of the data set defined in the report. In your case, that would be

rds.Name = "dtaset1_m_guest"; 
Hello爱情风 2024-09-14 18:53:05

确保 rdl 文件中的数据集名称与报告生成器匹配!

最简单的方法是拥有一个数据集、数据源和名为“M_GUEST”的实例。另外,渲染前不要清除数据源。

Make sure the names of datasets in the rdl file and the report generator match!

The easiest way would be to have a DataSet, DataSource and the instances named "M_GUEST". Also, do not clear the data sources before rendering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文