.rdl 报告未在 C# 中显示

.rdl report not showing in C#

我使用 SQL Server Business Intelligence Development Studio 2008 R2 创建了一个 rdl 报告。

我使用了一个简单的查询

Select top 10 id from login_user where client_id =3

预览显示数据如下

然后我创建一个带有报表查看器和命令按钮的 c# window 应用程序。 点击按钮我写了下面的代码

SqlConnection conn = new SqlConnection(connstring);
DataSet dataset = new DataSet();
 conn.Open();
sqlcomm = new SqlCommand("Select top 10 id from login_user where client_id = "+ 32, conn);
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcomm);
dataAdapter.Fill(dataset);
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\Report1.rdl";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("TotalSale", dataset.Tables[0]));
this.reportViewer1.RefreshReport();

它执行成功,但报表查看器没有显示它给出消息的报表

a datasource instance has not been supplied for the datasource

是因为我用的是.rdl吗?只有 rdlc 可以与 .net 一起使用吗?我被困在这里。

在这一行

this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("TotalSale", dataset.Tables[0]));

将"TotalSale"替换为"DatSet1"

因为您在报表中的数据集名称是DataSet1。