C# 如何使用编码运行rdlc

C# 如何使用编码运行rdlc,c#,crystal-reports,dataset,reporting,rdlc,C#,Crystal Reports,Dataset,Reporting,Rdlc,我已经创建了一个rdlc,在这里我将数据集作为解决方案资源管理器中的一个新项用于设计我的报告。从名为Dataset1的数据源绑定我的报告后。我已经创建了它的对象,并尝试使用编码填充此数据源。现在,当我运行下面的代码时,我没有得到任何结果 问题是什么 reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local; LocalReport localReport = reportViewer1.Loc

我已经创建了一个
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”提供数据源实例


确保rdl文件和报表生成器中的数据集名称匹配

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

此行

rds.Name = "AA"; 
必须与报表中定义的数据集的名称匹配。对你来说,那就是

rds.Name = "dtaset1_m_guest"; 

当您通过向导在项目中添加.rdlc报表时,默认情况下,它将数据集名称作为“DataSet1”。现在,若要动态绑定新数据集,那个么该数据集的名称必须是“DataSet1”。请尝试更改它,并检查表[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报告(核心逻辑)的更多详细信息,请参阅以下链接

如果绑定中的数据源名为“Dataset1”,则代码中的数据源也应命名为相同的数据源

我这样添加,效果非常好,如下所示:

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